FileDocCategorySizeDatePackage
WifiConfiguration.javaAPI DocAndroid 5.1 API61595Thu Mar 12 22:22:44 GMT 2015android.net.wifi

WifiConfiguration

public class WifiConfiguration extends Object implements android.os.Parcelable
A class representing a configured Wi-Fi network, including the security configuration.

Fields Summary
private static final String
TAG
public static final String
ssidVarName
{@hide}
public static final String
bssidVarName
{@hide}
public static final String
pskVarName
{@hide}
public static final String[]
wepKeyVarNames
{@hide}
public static final String
wepTxKeyIdxVarName
{@hide}
public static final String
priorityVarName
{@hide}
public static final String
hiddenSSIDVarName
{@hide}
public static final String
pmfVarName
{@hide}
public static final String
updateIdentiferVarName
{@hide}
public static final int
INVALID_NETWORK_ID
{@hide}
public static final int
DISABLED_UNKNOWN_REASON
public static final int
DISABLED_DNS_FAILURE
public static final int
DISABLED_DHCP_FAILURE
public static final int
DISABLED_AUTH_FAILURE
public static final int
DISABLED_ASSOCIATION_REJECT
public static final int
DISABLED_BY_WIFI_MANAGER
public int
networkId
The ID number that the supplicant uses to identify this network configuration entry. This must be passed as an argument to most calls into the supplicant.
public int
status
The current status of this network configuration entry.
public boolean
dirty
The configuration needs to be written to networkHistory.txt
public int
disableReason
The code referring to a reason for disabling the network Valid when {@link #status} == Status.DISABLED
public String
SSID
The network's SSID. Can either be an ASCII string, which must be enclosed in double quotation marks (e.g., {@code "MyNetwork"}, or a string of hex digits,which are not enclosed in quotes (e.g., {@code 01a243f405}).
public String
BSSID
When set, this network configuration entry should only be used when associating with the AP having the specified BSSID. The value is a string in the format of an Ethernet MAC address, e.g., XX:XX:XX:XX:XX:XX where each X is a hex digit.
public String
FQDN
Fully qualified domain name (FQDN) of AAA server or RADIUS server e.g. {@code "mail.example.com"}.
public String
naiRealm
Network access identifier (NAI) realm, for Passpoint credential. e.g. {@code "myhost.example.com"}.
public String
preSharedKey
Pre-shared key for use with WPA-PSK.

When the value of this key is read, the actual key is not returned, just a "*" if the key has a value, or the null string otherwise.

public String[]
wepKeys
Up to four WEP keys. Either an ASCII string enclosed in double quotation marks (e.g., {@code "abcdef"} or a string of hex digits (e.g., {@code 0102030405}).

When the value of one of these keys is read, the actual key is not returned, just a "*" if the key has a value, or the null string otherwise.

public int
wepTxKeyIndex
Default WEP key index, ranging from 0 to 3.
public int
priority
Priority determines the preference given to a network by {@code wpa_supplicant} when choosing an access point with which to associate.
public boolean
hiddenSSID
This is a network that does not broadcast its SSID, so an SSID-specific probe request must be used for scans.
public boolean
requirePMF
This is a network that requries Protected Management Frames (PMF).
public String
updateIdentifier
Update identifier, for Passpoint network.
public BitSet
allowedKeyManagement
The set of key management protocols supported by this configuration. See {@link KeyMgmt} for descriptions of the values. Defaults to WPA-PSK WPA-EAP.
public BitSet
allowedProtocols
The set of security protocols supported by this configuration. See {@link Protocol} for descriptions of the values. Defaults to WPA RSN.
public BitSet
allowedAuthAlgorithms
The set of authentication protocols supported by this configuration. See {@link AuthAlgorithm} for descriptions of the values. Defaults to automatic selection.
public BitSet
allowedPairwiseCiphers
The set of pairwise ciphers for WPA supported by this configuration. See {@link PairwiseCipher} for descriptions of the values. Defaults to CCMP TKIP.
public BitSet
allowedGroupCiphers
The set of group ciphers supported by this configuration. See {@link GroupCipher} for descriptions of the values. Defaults to CCMP TKIP WEP104 WEP40.
public WifiEnterpriseConfig
enterpriseConfig
The enterprise configuration details specifying the EAP method, certificates and other settings associated with the EAP.
private android.net.IpConfiguration
mIpConfiguration
public String
dhcpServer
public String
defaultGwMacAddress
public String
lastFailure
public boolean
validatedInternetAccess
public int
creatorUid
public int
lastConnectUid
public int
lastUpdateUid
public String
autoJoinBSSID
public HashMap
scanResultCache
public static int
INVALID_RSSI
public static int
UNWANTED_BLACKLIST_SOFT_RSSI_24
public static int
UNWANTED_BLACKLIST_SOFT_RSSI_5
public static int
GOOD_RSSI_24
public static int
LOW_RSSI_24
public static int
BAD_RSSI_24
public static int
GOOD_RSSI_5
public static int
LOW_RSSI_5
public static int
BAD_RSSI_5
public static int
UNWANTED_BLACKLIST_SOFT_BUMP
public static int
UNWANTED_BLACKLIST_HARD_BUMP
public static int
UNBLACKLIST_THRESHOLD_24_SOFT
public static int
UNBLACKLIST_THRESHOLD_24_HARD
public static int
UNBLACKLIST_THRESHOLD_5_SOFT
public static int
UNBLACKLIST_THRESHOLD_5_HARD
public static int
INITIAL_AUTO_JOIN_ATTEMPT_MIN_24
public static int
INITIAL_AUTO_JOIN_ATTEMPT_MIN_5
public static int
A_BAND_PREFERENCE_RSSI_THRESHOLD
public static int
G_BAND_PREFERENCE_RSSI_THRESHOLD
public static int
HOME_NETWORK_RSSI_BOOST
public static int
MAX_INITIAL_AUTO_JOIN_RSSI_BOOST
public Visibility
visibility
public static final int
AUTO_JOIN_ENABLED
public static final int
AUTO_JOIN_TEMPORARY_DISABLED
public static final int
AUTO_JOIN_TEMPORARY_DISABLED_LINK_ERRORS
public static final int
AUTO_JOIN_TEMPORARY_DISABLED_AT_SUPPLICANT
public static final int
AUTO_JOIN_DISABLED_ON_AUTH_FAILURE
public static final int
AUTO_JOIN_DISABLED_NO_CREDENTIALS
public static final int
AUTO_JOIN_DISABLED_USER_ACTION
public static final int
AUTO_JOIN_DELETED
public int
autoJoinStatus
public int
numConnectionFailures
public int
numIpConfigFailures
public int
numAuthFailures
public int
numNoInternetAccessReports
public long
blackListTimestamp
public long
lastConnected
public long
lastConnectionFailure
public long
lastRoamingFailure
public static int
ROAMING_FAILURE_IP_CONFIG
public static int
ROAMING_FAILURE_AUTH_FAILURE
public long
roamingFailureBlackListTimeMilli
public int
lastRoamingFailureReason
public long
lastDisconnected
public boolean
selfAdded
Set if the configuration was self added by the framework This boolean is cleared if we get a connect/save/ update or any wifiManager command that indicate the user interacted with the configuration since we will now consider that the configuration belong to him.
public boolean
didSelfAdd
Set if the configuration was self added by the framework This boolean is set once and never cleared. It is used so as we never loose track of who created the configuration in the first place.
public String
peerWifiConfiguration
Peer WifiConfiguration this WifiConfiguration was added for
public boolean
ephemeral
public boolean
autoJoinBailedDueToLowRssi
public int
autoJoinUseAggressiveJoinAttemptThreshold
public int
numScorerOverride
public int
numScorerOverrideAndSwitchedNetwork
public int
numAssociation
public int
numUserTriggeredWifiDisableLowRSSI
public int
numUserTriggeredWifiDisableBadRSSI
public int
numUserTriggeredWifiDisableNotHighRSSI
public int
numTicksAtLowRSSI
public int
numTicksAtBadRSSI
public int
numTicksAtNotHighRSSI
public int
numUserTriggeredJoinAttempts
public HashMap
connectChoices
public HashMap
linkedConfigurations
String
mCachedConfigKey
public static final Creator
CREATOR
Implement the Parcelable interface {@hide}
Constructors Summary
public WifiConfiguration()


      
        networkId = INVALID_NETWORK_ID;
        SSID = null;
        BSSID = null;
        FQDN = null;
        naiRealm = null;
        priority = 0;
        hiddenSSID = false;
        disableReason = DISABLED_UNKNOWN_REASON;
        allowedKeyManagement = new BitSet();
        allowedProtocols = new BitSet();
        allowedAuthAlgorithms = new BitSet();
        allowedPairwiseCiphers = new BitSet();
        allowedGroupCiphers = new BitSet();
        wepKeys = new String[4];
        for (int i = 0; i < wepKeys.length; i++) {
            wepKeys[i] = null;
        }
        enterpriseConfig = new WifiEnterpriseConfig();
        autoJoinStatus = AUTO_JOIN_ENABLED;
        selfAdded = false;
        didSelfAdd = false;
        ephemeral = false;
        validatedInternetAccess = false;
        mIpConfiguration = new IpConfiguration();
    
public WifiConfiguration(WifiConfiguration source)
copy constructor {@hide}

        if (source != null) {
            networkId = source.networkId;
            status = source.status;
            disableReason = source.disableReason;
            disableReason = source.disableReason;
            SSID = source.SSID;
            BSSID = source.BSSID;
            FQDN = source.FQDN;
            naiRealm = source.naiRealm;
            preSharedKey = source.preSharedKey;

            wepKeys = new String[4];
            for (int i = 0; i < wepKeys.length; i++) {
                wepKeys[i] = source.wepKeys[i];
            }

            wepTxKeyIndex = source.wepTxKeyIndex;
            priority = source.priority;
            hiddenSSID = source.hiddenSSID;
            allowedKeyManagement   = (BitSet) source.allowedKeyManagement.clone();
            allowedProtocols       = (BitSet) source.allowedProtocols.clone();
            allowedAuthAlgorithms  = (BitSet) source.allowedAuthAlgorithms.clone();
            allowedPairwiseCiphers = (BitSet) source.allowedPairwiseCiphers.clone();
            allowedGroupCiphers    = (BitSet) source.allowedGroupCiphers.clone();

            enterpriseConfig = new WifiEnterpriseConfig(source.enterpriseConfig);

            defaultGwMacAddress = source.defaultGwMacAddress;

            mIpConfiguration = new IpConfiguration(source.mIpConfiguration);

            if ((source.scanResultCache != null) && (source.scanResultCache.size() > 0)) {
                scanResultCache = new HashMap<String, ScanResult>();
                scanResultCache.putAll(source.scanResultCache);
            }

            if ((source.connectChoices != null) && (source.connectChoices.size() > 0)) {
                connectChoices = new HashMap<String, Integer>();
                connectChoices.putAll(source.connectChoices);
            }

            if ((source.linkedConfigurations != null)
                    && (source.linkedConfigurations.size() > 0)) {
                linkedConfigurations = new HashMap<String, Integer>();
                linkedConfigurations.putAll(source.linkedConfigurations);
            }
            mCachedConfigKey = null; //force null configKey
            autoJoinStatus = source.autoJoinStatus;
            selfAdded = source.selfAdded;
            validatedInternetAccess = source.validatedInternetAccess;
            ephemeral = source.ephemeral;
            if (source.visibility != null) {
                visibility = new Visibility(source.visibility);
            }

            lastFailure = source.lastFailure;
            didSelfAdd = source.didSelfAdd;
            lastConnectUid = source.lastConnectUid;
            lastUpdateUid = source.lastUpdateUid;
            creatorUid = source.creatorUid;
            peerWifiConfiguration = source.peerWifiConfiguration;
            blackListTimestamp = source.blackListTimestamp;
            lastConnected = source.lastConnected;
            lastDisconnected = source.lastDisconnected;
            lastConnectionFailure = source.lastConnectionFailure;
            lastRoamingFailure = source.lastRoamingFailure;
            lastRoamingFailureReason = source.lastRoamingFailureReason;
            roamingFailureBlackListTimeMilli = source.roamingFailureBlackListTimeMilli;
            numConnectionFailures = source.numConnectionFailures;
            numIpConfigFailures = source.numIpConfigFailures;
            numAuthFailures = source.numAuthFailures;
            numScorerOverride = source.numScorerOverride;
            numScorerOverrideAndSwitchedNetwork = source.numScorerOverrideAndSwitchedNetwork;
            numAssociation = source.numAssociation;
            numUserTriggeredWifiDisableLowRSSI = source.numUserTriggeredWifiDisableLowRSSI;
            numUserTriggeredWifiDisableBadRSSI = source.numUserTriggeredWifiDisableBadRSSI;
            numUserTriggeredWifiDisableNotHighRSSI = source.numUserTriggeredWifiDisableNotHighRSSI;
            numTicksAtLowRSSI = source.numTicksAtLowRSSI;
            numTicksAtBadRSSI = source.numTicksAtBadRSSI;
            numTicksAtNotHighRSSI = source.numTicksAtNotHighRSSI;
            numUserTriggeredJoinAttempts = source.numUserTriggeredJoinAttempts;
            autoJoinBSSID = source.autoJoinBSSID;
            autoJoinUseAggressiveJoinAttemptThreshold
                    = source.autoJoinUseAggressiveJoinAttemptThreshold;
            autoJoinBailedDueToLowRssi = source.autoJoinBailedDueToLowRssi;
            dirty = source.dirty;
            numNoInternetAccessReports = source.numNoInternetAccessReports;
        }
    
Methods Summary
public java.lang.StringconfigKey(boolean allowCached)

hide
return the string used to calculate the hash in WifiConfigStore and uniquely identify this WifiConfiguration

        String key;
        if (allowCached && mCachedConfigKey != null) {
            key = mCachedConfigKey;
        } else {
            if (allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
                key = SSID + KeyMgmt.strings[KeyMgmt.WPA_PSK];
            } else if (allowedKeyManagement.get(KeyMgmt.WPA_EAP) ||
                    allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
                key = SSID + KeyMgmt.strings[KeyMgmt.WPA_EAP];
            } else if (wepKeys[0] != null) {
                key = SSID + "WEP";
            } else {
                key = SSID + KeyMgmt.strings[KeyMgmt.NONE];
            }
            mCachedConfigKey = key;
        }
        return key;
    
public java.lang.StringconfigKey()

hide
get configKey, force calculating the config string

        return configKey(false);
    
public static java.lang.StringconfigKey(ScanResult result)

hide
return the config key string based on a scan result

        String key = "\"" + result.SSID + "\"";

        if (result.capabilities.contains("WEP")) {
            key = key + "-WEP";
        }

        if (result.capabilities.contains("PSK")) {
            key = key + "-" + KeyMgmt.strings[KeyMgmt.WPA_PSK];
        }

        if (result.capabilities.contains("EAP")) {
            key = key + "-" + KeyMgmt.strings[KeyMgmt.WPA_EAP];
        }

        return key;
    
public intdescribeContents()
Implement the Parcelable interface {@hide}

        return 0;
    
public intgetAuthType()

hide

        if (isValid() == false) {
            throw new IllegalStateException("Invalid configuration");
        }
        if (allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
            return KeyMgmt.WPA_PSK;
        } else if (allowedKeyManagement.get(KeyMgmt.WPA2_PSK)) {
            return KeyMgmt.WPA2_PSK;
        } else if (allowedKeyManagement.get(KeyMgmt.WPA_EAP)) {
            return KeyMgmt.WPA_EAP;
        } else if (allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
            return KeyMgmt.IEEE8021X;
        }
        return KeyMgmt.NONE;
    
public android.net.ProxyInfogetHttpProxy()

hide

        return mIpConfiguration.httpProxy;
    
public android.net.IpConfiguration.IpAssignmentgetIpAssignment()

hide

        return mIpConfiguration.ipAssignment;
    
public android.net.IpConfigurationgetIpConfiguration()

hide

        return mIpConfiguration;
    
public java.lang.StringgetKeyIdForCredentials(android.net.wifi.WifiConfiguration current)
Get an identifier for associating credentials with this config

param
current configuration contains values for additional fields that are not part of this configuration. Used when a config with some fields is passed by an application.
throws
IllegalStateException if config is invalid for key id generation
hide

        String keyMgmt = null;

        try {
            // Get current config details for fields that are not initialized
            if (TextUtils.isEmpty(SSID)) SSID = current.SSID;
            if (allowedKeyManagement.cardinality() == 0) {
                allowedKeyManagement = current.allowedKeyManagement;
            }
            if (allowedKeyManagement.get(KeyMgmt.WPA_EAP)) {
                keyMgmt = KeyMgmt.strings[KeyMgmt.WPA_EAP];
            }
            if (allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
                keyMgmt += KeyMgmt.strings[KeyMgmt.IEEE8021X];
            }

            if (TextUtils.isEmpty(keyMgmt)) {
                throw new IllegalStateException("Not an EAP network");
            }

            return trimStringForKeyId(SSID) + "_" + keyMgmt + "_" +
                    trimStringForKeyId(enterpriseConfig.getKeyId(current != null ?
                            current.enterpriseConfig : null));
        } catch (NullPointerException e) {
            throw new IllegalStateException("Invalid config details");
        }
    
public java.lang.StringgetPrintableSsid()
{@hide}

        if (SSID == null) return "";
        final int length = SSID.length();
        if (length > 2 && (SSID.charAt(0) == '"") && SSID.charAt(length - 1) == '"") {
            return SSID.substring(1, length - 1);
        }

        /** The ascii-encoded string format is P"<ascii-encoded-string>"
         * The decoding is implemented in the supplicant for a newly configured
         * network.
         */
        if (length > 3 && (SSID.charAt(0) == 'P") && (SSID.charAt(1) == '"") &&
                (SSID.charAt(length-1) == '"")) {
            WifiSsid wifiSsid = WifiSsid.createFromAsciiEncoded(
                    SSID.substring(2, length - 1));
            return wifiSsid.toString();
        }
        return SSID;
    
public android.net.IpConfiguration.ProxySettingsgetProxySettings()

hide

        return mIpConfiguration.proxySettings;
    
public android.net.StaticIpConfigurationgetStaticIpConfiguration()

hide

        return mIpConfiguration.getStaticIpConfiguration();
    
public booleanhasNoInternetAccess()

hide
The WiFi configuration is considered to have no internet access for purpose of autojoining if there has been a report of it having no internet access, and, it never have had internet access in the past.


                                              
       
        return numNoInternetAccessReports > 0 && !validatedInternetAccess;
    
public booleanisLinked(android.net.wifi.WifiConfiguration config)
Helper function, identify if a configuration is linked

hide

        if (config.linkedConfigurations != null && linkedConfigurations != null) {
            if (config.linkedConfigurations.get(configKey()) != null
                    && linkedConfigurations.get(config.configKey()) != null) {
                return true;
            }
        }
        return  false;
    
public booleanisValid()
indicates whether the configuration is valid

return
true if valid, false otherwise
hide


        if (allowedKeyManagement == null)
            return false;

        if (allowedKeyManagement.cardinality() > 1) {
            if (allowedKeyManagement.cardinality() != 2) {
                return false;
            }
            if (allowedKeyManagement.get(KeyMgmt.WPA_EAP) == false) {
                return false;
            }
            if ((allowedKeyManagement.get(KeyMgmt.IEEE8021X) == false)
                    && (allowedKeyManagement.get(KeyMgmt.WPA_PSK) == false)) {
                return false;
            }
        }

        // TODO: Add more checks
        return true;
    
public ScanResultlastSeen()
most recent time we have seen this configuration

return
most recent scanResult
hide

        ScanResult mostRecent = null;

        if (scanResultCache == null) {
            return null;
        }

        for (ScanResult result : scanResultCache.values()) {
            if (mostRecent == null) {
                if (result.seen != 0)
                   mostRecent = result;
            } else {
                if (result.seen > mostRecent.seen) {
                   mostRecent = result;
                }
            }
        }
        return mostRecent;
    
private static java.util.BitSetreadBitSet(android.os.Parcel src)

        int cardinality = src.readInt();

        BitSet set = new BitSet();
        for (int i = 0; i < cardinality; i++) {
            set.set(src.readInt());
        }

        return set;
    
public voidsetAutoJoinStatus(int status)

hide

        if (status < 0) status = 0;
        if (status == 0) {
            blackListTimestamp = 0;
        }  else if (status > autoJoinStatus) {
            blackListTimestamp = System.currentTimeMillis();
        }
        if (status != autoJoinStatus) {
            autoJoinStatus = status;
            dirty = true;
        }
    
public voidsetHttpProxy(android.net.ProxyInfo httpProxy)

hide

        mIpConfiguration.httpProxy = httpProxy;
    
public voidsetIpAssignment(android.net.IpConfiguration.IpAssignment ipAssignment)

hide

        mIpConfiguration.ipAssignment = ipAssignment;
    
public voidsetIpConfiguration(android.net.IpConfiguration ipConfiguration)

hide

        mIpConfiguration = ipConfiguration;
    
public voidsetProxy(android.net.IpConfiguration.ProxySettings settings, android.net.ProxyInfo proxy)

hide

        mIpConfiguration.proxySettings = settings;
        mIpConfiguration.httpProxy = proxy;
    
public voidsetProxySettings(android.net.IpConfiguration.ProxySettings proxySettings)

hide

        mIpConfiguration.proxySettings = proxySettings;
    
public voidsetStaticIpConfiguration(android.net.StaticIpConfiguration staticIpConfiguration)

hide

        mIpConfiguration.setStaticIpConfiguration(staticIpConfiguration);
    
public android.net.wifi.WifiConfiguration$VisibilitysetVisibility(long age)

hide
calculate and set Visibility for that configuration. age in milliseconds: we will consider only ScanResults that are more recent, i.e. younger.

        if (scanResultCache == null) {
            visibility = null;
            return null;
        }

        Visibility status = new Visibility();

        long now_ms = System.currentTimeMillis();
        for(ScanResult result : scanResultCache.values()) {
            if (result.seen == 0)
                continue;

            if (result.is5GHz()) {
                //strictly speaking: [4915, 5825]
                //number of known BSSID on 5GHz band
                status.num5 = status.num5 + 1;
            } else if (result.is24GHz()) {
                //strictly speaking: [2412, 2482]
                //number of known BSSID on 2.4Ghz band
                status.num24 = status.num24 + 1;
            }

            if ((now_ms - result.seen) > age) continue;

            if (result.is5GHz()) {
                if (result.level > status.rssi5) {
                    status.rssi5 = result.level;
                    status.age5 = result.seen;
                    status.BSSID5 = result.BSSID;
                }
            } else if (result.is24GHz()) {
                if (result.level > status.rssi24) {
                    status.rssi24 = result.level;
                    status.age24 = result.seen;
                    status.BSSID24 = result.BSSID;
                }
            }
        }
        visibility = status;
        return status;
    
private java.util.ArrayListsortScanResults()

        ArrayList<ScanResult> list = new ArrayList<ScanResult>(this.scanResultCache.values());
        if (list.size() != 0) {
            Collections.sort(list, new Comparator() {
                public int compare(Object o1, Object o2) {
                    ScanResult a = (ScanResult)o1;
                    ScanResult b = (ScanResult)o2;
                    if (a.numIpConfigFailures > b.numIpConfigFailures) {
                        return 1;
                    }
                    if (a.numIpConfigFailures < b.numIpConfigFailures) {
                        return -1;
                    }
                    if (a.seen > b.seen) {
                        return -1;
                    }
                    if (a.seen < b.seen) {
                        return 1;
                    }
                    if (a.level > b.level) {
                        return -1;
                    }
                    if (a.level < b.level) {
                        return 1;
                    }
                    return a.BSSID.compareTo(b.BSSID);
                }
            });
        }
        return list;
    
public java.lang.StringtoString()

        StringBuilder sbuf = new StringBuilder();
        if (this.status == WifiConfiguration.Status.CURRENT) {
            sbuf.append("* ");
        } else if (this.status == WifiConfiguration.Status.DISABLED) {
            sbuf.append("- DSBLE ");
        }
        sbuf.append("ID: ").append(this.networkId).append(" SSID: ").append(this.SSID).
                append(" BSSID: ").append(this.BSSID).append(" FQDN: ").append(this.FQDN).
                append(" REALM: ").append(this.naiRealm).append(" PRIO: ").append(this.priority).
                append('\n");
        if (this.numConnectionFailures > 0) {
            sbuf.append(" numConnectFailures ").append(this.numConnectionFailures).append("\n");
        }
        if (this.numIpConfigFailures > 0) {
            sbuf.append(" numIpConfigFailures ").append(this.numIpConfigFailures).append("\n");
        }
        if (this.numAuthFailures > 0) {
            sbuf.append(" numAuthFailures ").append(this.numAuthFailures).append("\n");
        }
        if (this.autoJoinStatus > 0) {
            sbuf.append(" autoJoinStatus ").append(this.autoJoinStatus).append("\n");
        }
        if (this.disableReason > 0) {
            sbuf.append(" disableReason ").append(this.disableReason).append("\n");
        }
        if (this.numAssociation > 0) {
            sbuf.append(" numAssociation ").append(this.numAssociation).append("\n");
        }
        if (this.numNoInternetAccessReports > 0) {
            sbuf.append(" numNoInternetAccessReports ");
            sbuf.append(this.numNoInternetAccessReports).append("\n");
        }
        if (this.didSelfAdd) sbuf.append(" didSelfAdd");
        if (this.selfAdded) sbuf.append(" selfAdded");
        if (this.validatedInternetAccess) sbuf.append(" validatedInternetAccess");
        if (this.ephemeral) sbuf.append(" ephemeral");
        if (this.didSelfAdd || this.selfAdded || this.validatedInternetAccess || this.ephemeral) {
            sbuf.append("\n");
        }
        sbuf.append(" KeyMgmt:");
        for (int k = 0; k < this.allowedKeyManagement.size(); k++) {
            if (this.allowedKeyManagement.get(k)) {
                sbuf.append(" ");
                if (k < KeyMgmt.strings.length) {
                    sbuf.append(KeyMgmt.strings[k]);
                } else {
                    sbuf.append("??");
                }
            }
        }
        sbuf.append(" Protocols:");
        for (int p = 0; p < this.allowedProtocols.size(); p++) {
            if (this.allowedProtocols.get(p)) {
                sbuf.append(" ");
                if (p < Protocol.strings.length) {
                    sbuf.append(Protocol.strings[p]);
                } else {
                    sbuf.append("??");
                }
            }
        }
        sbuf.append('\n");
        sbuf.append(" AuthAlgorithms:");
        for (int a = 0; a < this.allowedAuthAlgorithms.size(); a++) {
            if (this.allowedAuthAlgorithms.get(a)) {
                sbuf.append(" ");
                if (a < AuthAlgorithm.strings.length) {
                    sbuf.append(AuthAlgorithm.strings[a]);
                } else {
                    sbuf.append("??");
                }
            }
        }
        sbuf.append('\n");
        sbuf.append(" PairwiseCiphers:");
        for (int pc = 0; pc < this.allowedPairwiseCiphers.size(); pc++) {
            if (this.allowedPairwiseCiphers.get(pc)) {
                sbuf.append(" ");
                if (pc < PairwiseCipher.strings.length) {
                    sbuf.append(PairwiseCipher.strings[pc]);
                } else {
                    sbuf.append("??");
                }
            }
        }
        sbuf.append('\n");
        sbuf.append(" GroupCiphers:");
        for (int gc = 0; gc < this.allowedGroupCiphers.size(); gc++) {
            if (this.allowedGroupCiphers.get(gc)) {
                sbuf.append(" ");
                if (gc < GroupCipher.strings.length) {
                    sbuf.append(GroupCipher.strings[gc]);
                } else {
                    sbuf.append("??");
                }
            }
        }
        sbuf.append('\n").append(" PSK: ");
        if (this.preSharedKey != null) {
            sbuf.append('*");
        }
        sbuf.append("\nEnterprise config:\n");
        sbuf.append(enterpriseConfig);

        sbuf.append("IP config:\n");
        sbuf.append(mIpConfiguration.toString());

        if (this.creatorUid != 0)  sbuf.append(" uid=" + Integer.toString(creatorUid));
        if (this.autoJoinBSSID != null) sbuf.append(" autoJoinBSSID=" + autoJoinBSSID);
        long now_ms = System.currentTimeMillis();
        if (this.blackListTimestamp != 0) {
            sbuf.append('\n");
            long diff = now_ms - this.blackListTimestamp;
            if (diff <= 0) {
                sbuf.append(" blackListed since <incorrect>");
            } else {
                sbuf.append(" blackListed: ").append(Long.toString(diff/1000)).append( "sec");
            }
        }
        if (this.lastConnected != 0) {
            sbuf.append('\n");
            long diff = now_ms - this.lastConnected;
            if (diff <= 0) {
                sbuf.append("lastConnected since <incorrect>");
            } else {
                sbuf.append("lastConnected: ").append(Long.toString(diff/1000)).append( "sec");
            }
        }
        if (this.lastConnectionFailure != 0) {
            sbuf.append('\n");
            long diff = now_ms - this.lastConnectionFailure;
            if (diff <= 0) {
                sbuf.append("lastConnectionFailure since <incorrect>");
            } else {
                sbuf.append("lastConnectionFailure: ").append(Long.toString(diff/1000));
                sbuf.append( "sec");
            }
        }
        if (this.lastRoamingFailure != 0) {
            sbuf.append('\n");
            long diff = now_ms - this.lastRoamingFailure;
            if (diff <= 0) {
                sbuf.append("lastRoamingFailure since <incorrect>");
            } else {
                sbuf.append("lastRoamingFailure: ").append(Long.toString(diff/1000));
                sbuf.append( "sec");
            }
        }
        sbuf.append("roamingFailureBlackListTimeMilli: ").
                append(Long.toString(this.roamingFailureBlackListTimeMilli));
        sbuf.append('\n");
        if (this.linkedConfigurations != null) {
            for(String key : this.linkedConfigurations.keySet()) {
                sbuf.append(" linked: ").append(key);
                sbuf.append('\n");
            }
        }
        if (this.connectChoices != null) {
            for(String key : this.connectChoices.keySet()) {
                Integer choice = this.connectChoices.get(key);
                if (choice != null) {
                    sbuf.append(" choice: ").append(key);
                    sbuf.append(" = ").append(choice);
                    sbuf.append('\n");
                }
            }
        }
        if (this.scanResultCache != null) {
            sbuf.append("Scan Cache:  ").append('\n");
            ArrayList<ScanResult> list = sortScanResults();
            if (list.size() > 0) {
                for (ScanResult result : list) {
                    long milli = now_ms - result.seen;
                    long ageSec = 0;
                    long ageMin = 0;
                    long ageHour = 0;
                    long ageMilli = 0;
                    long ageDay = 0;
                    if (now_ms > result.seen && result.seen > 0) {
                        ageMilli = milli % 1000;
                        ageSec   = (milli / 1000) % 60;
                        ageMin   = (milli / (60*1000)) % 60;
                        ageHour  = (milli / (60*60*1000)) % 24;
                        ageDay   = (milli / (24*60*60*1000));
                    }
                    sbuf.append("{").append(result.BSSID).append(",").append(result.frequency);
                    sbuf.append(",").append(String.format("%3d", result.level));
                    if (result.autoJoinStatus > 0) {
                        sbuf.append(",st=").append(result.autoJoinStatus);
                    }
                    if (ageSec > 0 || ageMilli > 0) {
                        sbuf.append(String.format(",%4d.%02d.%02d.%02d.%03dms", ageDay,
                                ageHour, ageMin, ageSec, ageMilli));
                    }
                    if (result.numIpConfigFailures > 0) {
                        sbuf.append(",ipfail=");
                        sbuf.append(result.numIpConfigFailures);
                    }
                    sbuf.append("} ");
                }
                sbuf.append('\n");
            }
        }
        sbuf.append("triggeredLow: ").append(this.numUserTriggeredWifiDisableLowRSSI);
        sbuf.append(" triggeredBad: ").append(this.numUserTriggeredWifiDisableBadRSSI);
        sbuf.append(" triggeredNotHigh: ").append(this.numUserTriggeredWifiDisableNotHighRSSI);
        sbuf.append('\n");
        sbuf.append("ticksLow: ").append(this.numTicksAtLowRSSI);
        sbuf.append(" ticksBad: ").append(this.numTicksAtBadRSSI);
        sbuf.append(" ticksNotHigh: ").append(this.numTicksAtNotHighRSSI);
        sbuf.append('\n");
        sbuf.append("triggeredJoin: ").append(this.numUserTriggeredJoinAttempts);
        sbuf.append('\n");
        sbuf.append("autoJoinBailedDueToLowRssi: ").append(this.autoJoinBailedDueToLowRssi);
        sbuf.append('\n");
        sbuf.append("autoJoinUseAggressiveJoinAttemptThreshold: ");
        sbuf.append(this.autoJoinUseAggressiveJoinAttemptThreshold);
        sbuf.append('\n");

        return sbuf.toString();
    
public voidtrimScanResultsCache(int num)

hide
trim the scan Result Cache
param:
number of entries to keep in the cache

        if (this.scanResultCache == null) {
            return;
        }
        int currenSize = this.scanResultCache.size();
        if (currenSize <= num) {
            return; // Nothing to trim
        }
        ArrayList<ScanResult> list = new ArrayList<ScanResult>(this.scanResultCache.values());
        if (list.size() != 0) {
            // Sort by descending timestamp
            Collections.sort(list, new Comparator() {
                public int compare(Object o1, Object o2) {
                    ScanResult a = (ScanResult)o1;
                    ScanResult b = (ScanResult)o2;
                    if (a.seen > b.seen) {
                        return 1;
                    }
                    if (a.seen < b.seen) {
                        return -1;
                    }
                    return a.BSSID.compareTo(b.BSSID);
                }
            });
        }
        for (int i = 0; i < currenSize - num ; i++) {
            // Remove oldest results from scan cache
            ScanResult result = list.get(i);
            this.scanResultCache.remove(result.BSSID);
        }
    
private java.lang.StringtrimStringForKeyId(java.lang.String string)

        // Remove quotes and spaces
        return string.replace("\"", "").replace(" ", "");
    
private static voidwriteBitSet(android.os.Parcel dest, java.util.BitSet set)

        int nextSetBit = -1;

        dest.writeInt(set.cardinality());

        while ((nextSetBit = set.nextSetBit(nextSetBit + 1)) != -1) {
            dest.writeInt(nextSetBit);
        }
    
public voidwriteToParcel(android.os.Parcel dest, int flags)
Implement the Parcelable interface {@hide}

        dest.writeInt(networkId);
        dest.writeInt(status);
        dest.writeInt(disableReason);
        dest.writeString(SSID);
        dest.writeString(BSSID);
        dest.writeString(autoJoinBSSID);
        dest.writeString(FQDN);
        dest.writeString(naiRealm);
        dest.writeString(preSharedKey);
        for (String wepKey : wepKeys) {
            dest.writeString(wepKey);
        }
        dest.writeInt(wepTxKeyIndex);
        dest.writeInt(priority);
        dest.writeInt(hiddenSSID ? 1 : 0);
        dest.writeInt(requirePMF ? 1 : 0);
        dest.writeString(updateIdentifier);

        writeBitSet(dest, allowedKeyManagement);
        writeBitSet(dest, allowedProtocols);
        writeBitSet(dest, allowedAuthAlgorithms);
        writeBitSet(dest, allowedPairwiseCiphers);
        writeBitSet(dest, allowedGroupCiphers);

        dest.writeParcelable(enterpriseConfig, flags);

        dest.writeParcelable(mIpConfiguration, flags);
        dest.writeString(dhcpServer);
        dest.writeString(defaultGwMacAddress);
        dest.writeInt(autoJoinStatus);
        dest.writeInt(selfAdded ? 1 : 0);
        dest.writeInt(didSelfAdd ? 1 : 0);
        dest.writeInt(validatedInternetAccess ? 1 : 0);
        dest.writeInt(ephemeral ? 1 : 0);
        dest.writeInt(creatorUid);
        dest.writeInt(lastConnectUid);
        dest.writeInt(lastUpdateUid);
        dest.writeLong(blackListTimestamp);
        dest.writeLong(lastConnectionFailure);
        dest.writeLong(lastRoamingFailure);
        dest.writeInt(lastRoamingFailureReason);
        dest.writeLong(roamingFailureBlackListTimeMilli);
        dest.writeInt(numConnectionFailures);
        dest.writeInt(numIpConfigFailures);
        dest.writeInt(numAuthFailures);
        dest.writeInt(numScorerOverride);
        dest.writeInt(numScorerOverrideAndSwitchedNetwork);
        dest.writeInt(numAssociation);
        dest.writeInt(numUserTriggeredWifiDisableLowRSSI);
        dest.writeInt(numUserTriggeredWifiDisableBadRSSI);
        dest.writeInt(numUserTriggeredWifiDisableNotHighRSSI);
        dest.writeInt(numTicksAtLowRSSI);
        dest.writeInt(numTicksAtBadRSSI);
        dest.writeInt(numTicksAtNotHighRSSI);
        dest.writeInt(numUserTriggeredJoinAttempts);
        dest.writeInt(autoJoinUseAggressiveJoinAttemptThreshold);
        dest.writeInt(autoJoinBailedDueToLowRssi ? 1 : 0);
        dest.writeInt(numNoInternetAccessReports);