FileDocCategorySizeDatePackage
WifiInfo.javaAPI DocAndroid 5.1 API18099Thu Mar 12 22:22:44 GMT 2015android.net.wifi

WifiInfo

public class WifiInfo extends Object implements android.os.Parcelable
Describes the state of any Wifi connection that is active or is in the process of being set up.

Fields Summary
private static final String
TAG
private static final EnumMap
stateMap
This is the map described in the Javadoc comment above. The positions of the elements of the array must correspond to the ordinal values of DetailedState.
private SupplicantState
mSupplicantState
private String
mBSSID
private WifiSsid
mWifiSsid
private int
mNetworkId
public static final int
INVALID_RSSI
public static final int
MIN_RSSI
public static final int
MAX_RSSI
private int
mRssi
Received Signal Strength Indicator
public static final String
LINK_SPEED_UNITS
Link speed in Mbps
private int
mLinkSpeed
public static final String
FREQUENCY_UNITS
Frequency in MHz
private int
mFrequency
private InetAddress
mIpAddress
private String
mMacAddress
public long
txBad
public long
txRetries
public long
txSuccess
public long
rxSuccess
public double
txBadRate
public double
txRetriesRate
public double
txSuccessRate
public double
rxSuccessRate
public int
badRssiCount
public int
linkStuckCount
public int
lowRssiCount
public int
score
private boolean
mMeteredHint
Flag indicating that AP has hinted that upstream connection is metered, and sensitive to heavy data transfers.
public static final Creator
CREATOR
Implement the Parcelable interface {@hide}
Constructors Summary
public WifiInfo()

hide

        mWifiSsid = null;
        mBSSID = null;
        mNetworkId = -1;
        mSupplicantState = SupplicantState.UNINITIALIZED;
        mRssi = INVALID_RSSI;
        mLinkSpeed = -1;
        mFrequency = -1;
    
public WifiInfo(WifiInfo source)
Copy constructor

hide

        if (source != null) {
            mSupplicantState = source.mSupplicantState;
            mBSSID = source.mBSSID;
            mWifiSsid = source.mWifiSsid;
            mNetworkId = source.mNetworkId;
            mRssi = source.mRssi;
            mLinkSpeed = source.mLinkSpeed;
            mFrequency = source.mFrequency;
            mIpAddress = source.mIpAddress;
            mMacAddress = source.mMacAddress;
            mMeteredHint = source.mMeteredHint;
            txBad = source.txBad;
            txRetries = source.txRetries;
            txSuccess = source.txSuccess;
            rxSuccess = source.rxSuccess;
            txBadRate = source.txBadRate;
            txRetriesRate = source.txRetriesRate;
            txSuccessRate = source.txSuccessRate;
            rxSuccessRate = source.rxSuccessRate;
            score = source.score;
            badRssiCount = source.badRssiCount;
            lowRssiCount = source.lowRssiCount;
            linkStuckCount = source.linkStuckCount;
        }
    
Methods Summary
public intdescribeContents()
Implement the Parcelable interface {@hide}

        return 0;
    
public java.lang.StringgetBSSID()
Return the basic service set identifier (BSSID) of the current access point. The BSSID may be {@code null} if there is no network currently connected.

return
the BSSID, in the form of a six-byte MAC address: {@code XX:XX:XX:XX:XX:XX}

        return mBSSID;
    
public static android.net.NetworkInfo.DetailedStategetDetailedStateOf(SupplicantState suppState)
Map a supplicant state into a fine-grained network connectivity state.

param
suppState the supplicant state
return
the corresponding {@link DetailedState}

        return stateMap.get(suppState);
    
public intgetFrequency()
Returns the current frequency in {@link #FREQUENCY_UNITS}.

return
the frequency.
see
#FREQUENCY_UNITS

        return mFrequency;
    
public booleangetHiddenSSID()

return
{@code true} if this network does not broadcast its SSID, so an SSID-specific probe request must be used for scans.

        if (mWifiSsid == null) return false;
        return mWifiSsid.isHidden();
    
public intgetIpAddress()

        int result = 0;
        if (mIpAddress instanceof Inet4Address) {
            result = NetworkUtils.inetAddressToInt((Inet4Address)mIpAddress);
        }
        return result;
    
public intgetLinkSpeed()
Returns the current link speed in {@link #LINK_SPEED_UNITS}.

return
the link speed.
see
#LINK_SPEED_UNITS

        return mLinkSpeed;
    
public java.lang.StringgetMacAddress()

        return mMacAddress;
    
public booleangetMeteredHint()
{@hide}

        return mMeteredHint;
    
public intgetNetworkId()
Each configured network has a unique small integer ID, used to identify the network when performing operations on the supplicant. This method returns the ID for the currently connected network.

return
the network ID, or -1 if there is no currently connected network

        return mNetworkId;
    
public intgetRssi()
Returns the received signal strength indicator of the current 802.11 network, in dBm.

Use {@link android.net.wifi.WifiManager#calculateSignalLevel} to convert this number into an absolute signal level which can be displayed to a user.

return
the RSSI.

        return mRssi;
    
public java.lang.StringgetSSID()
Returns the service set identifier (SSID) of the current 802.11 network. If the SSID can be decoded as UTF-8, it will be returned surrounded by double quotation marks. Otherwise, it is returned as a string of hex digits. The SSID may be <unknown ssid> if there is no network currently connected.

return
the SSID

        if (mWifiSsid != null) {
            String unicode = mWifiSsid.toString();
            if (!TextUtils.isEmpty(unicode)) {
                return "\"" + unicode + "\"";
            } else {
                return mWifiSsid.getHexString();
            }
        }
        return WifiSsid.NONE;
    
public SupplicantStategetSupplicantState()
Return the detailed state of the supplicant's negotiation with an access point, in the form of a {@link SupplicantState SupplicantState} object.

return
the current {@link SupplicantState SupplicantState}

        return mSupplicantState;
    
public WifiSsidgetWifiSsid()

hide

        return mWifiSsid;
    
public booleanis24GHz()

hide
TODO: makes real freq boundaries

        return ScanResult.is24GHz(mFrequency);
    
public booleanis5GHz()

hide
TODO: makes real freq boundaries

        return ScanResult.is5GHz(mFrequency);
    
public static java.lang.StringremoveDoubleQuotes(java.lang.String string)
{@hide}

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

hide

        setInetAddress(null);
        setBSSID(null);
        setSSID(null);
        setNetworkId(-1);
        setRssi(INVALID_RSSI);
        setLinkSpeed(-1);
        setFrequency(-1);
        setMeteredHint(false);
        txBad = 0;
        txSuccess = 0;
        rxSuccess = 0;
        txRetries = 0;
        txBadRate = 0;
        txSuccessRate = 0;
        rxSuccessRate = 0;
        txRetriesRate = 0;
        lowRssiCount = 0;
        badRssiCount = 0;
        linkStuckCount = 0;
        score = 0;
    
public voidsetBSSID(java.lang.String BSSID)

hide

        mBSSID = BSSID;
    
public voidsetFrequency(int frequency)

hide

        this.mFrequency = frequency;
    
public voidsetInetAddress(java.net.InetAddress address)

hide

        mIpAddress = address;
    
public voidsetLinkSpeed(int linkSpeed)

hide

        this.mLinkSpeed = linkSpeed;
    
public voidsetMacAddress(java.lang.String macAddress)
Record the MAC address of the WLAN interface

param
macAddress the MAC address in {@code XX:XX:XX:XX:XX:XX} form
hide

        this.mMacAddress = macAddress;
    
public voidsetMeteredHint(boolean meteredHint)
{@hide}

        mMeteredHint = meteredHint;
    
public voidsetNetworkId(int id)

hide

        mNetworkId = id;
    
public voidsetRssi(int rssi)

hide

        if (rssi < INVALID_RSSI)
            rssi = INVALID_RSSI;
        if (rssi > MAX_RSSI)
            rssi = MAX_RSSI;
        mRssi = rssi;
    
public voidsetSSID(WifiSsid wifiSsid)

hide

        mWifiSsid = wifiSsid;
    
public voidsetSupplicantState(SupplicantState state)

hide

        mSupplicantState = state;
    
voidsetSupplicantState(java.lang.String stateName)
Set the SupplicantState from the string name of the state.

param
stateName the name of the state, as a String returned in an event sent by {@code wpa_supplicant}.

        mSupplicantState = valueOf(stateName);
    
public java.lang.StringtoString()

        StringBuffer sb = new StringBuffer();
        String none = "<none>";

        sb.append("SSID: ").append(mWifiSsid == null ? WifiSsid.NONE : mWifiSsid).
            append(", BSSID: ").append(mBSSID == null ? none : mBSSID).
            append(", MAC: ").append(mMacAddress == null ? none : mMacAddress).
            append(", Supplicant state: ").
            append(mSupplicantState == null ? none : mSupplicantState).
            append(", RSSI: ").append(mRssi).
            append(", Link speed: ").append(mLinkSpeed).append(LINK_SPEED_UNITS).
            append(", Frequency: ").append(mFrequency).append(FREQUENCY_UNITS).
            append(", Net ID: ").append(mNetworkId).
            append(", Metered hint: ").append(mMeteredHint).
            append(", score: ").append(Integer.toString(score));
        return sb.toString();
    
public voidupdatePacketRates(WifiLinkLayerStats stats)
TODO: get actual timestamp and calculate true rates

hide


                  
        
        if (stats != null) {
            long txgood = stats.txmpdu_be + stats.txmpdu_bk + stats.txmpdu_vi + stats.txmpdu_vo;
            long txretries = stats.retries_be + stats.retries_bk
                    + stats.retries_vi + stats.retries_vo;
            long rxgood = stats.rxmpdu_be + stats.rxmpdu_bk + stats.rxmpdu_vi + stats.rxmpdu_vo;
            long txbad = stats.lostmpdu_be + stats.lostmpdu_bk
                    + stats.lostmpdu_vi + stats.lostmpdu_vo;

            txBadRate = (txBadRate * 0.5)
                + ((double) (txbad - txBad) * 0.5);
            txSuccessRate = (txSuccessRate * 0.5)
                + ((double) (txgood - txSuccess) * 0.5);
            rxSuccessRate = (rxSuccessRate * 0.5)
                + ((double) (rxgood - rxSuccess) * 0.5);
            txRetriesRate = (txRetriesRate * 0.5)
                + ((double) (txretries - txRetries) * 0.5);

            txBad = txbad;
            txSuccess = txgood;
            rxSuccess = rxgood;
            txRetries = txretries;
        } else {
            txBad = 0;
            txSuccess = 0;
            rxSuccess = 0;
            txRetries = 0;
            txBadRate = 0;
            txSuccessRate = 0;
            rxSuccessRate = 0;
            txRetriesRate = 0;
        }
    
public voidupdatePacketRates(long txPackets, long rxPackets)
This function is less powerful and used if the WifiLinkLayerStats API is not implemented at the Wifi HAL

hide

        //paranoia
        txBad = 0;
        txRetries = 0;
        txBadRate = 0;
        txRetriesRate = 0;

        txSuccessRate = (txSuccessRate * 0.5)
                + ((double) (txPackets - txSuccess) * 0.5);
        rxSuccessRate = (rxSuccessRate * 0.5)
                + ((double) (rxPackets - rxSuccess) * 0.5);
        txSuccess = txPackets;
        rxSuccess = rxPackets;
    
static SupplicantStatevalueOf(java.lang.String stateName)

        if ("4WAY_HANDSHAKE".equalsIgnoreCase(stateName))
            return SupplicantState.FOUR_WAY_HANDSHAKE;
        else {
            try {
                return SupplicantState.valueOf(stateName.toUpperCase(Locale.ROOT));
            } catch (IllegalArgumentException e) {
                return SupplicantState.INVALID;
            }
        }
    
public voidwriteToParcel(android.os.Parcel dest, int flags)
Implement the Parcelable interface {@hide}

        dest.writeInt(mNetworkId);
        dest.writeInt(mRssi);
        dest.writeInt(mLinkSpeed);
        dest.writeInt(mFrequency);
        if (mIpAddress != null) {
            dest.writeByte((byte)1);
            dest.writeByteArray(mIpAddress.getAddress());
        } else {
            dest.writeByte((byte)0);
        }
        if (mWifiSsid != null) {
            dest.writeInt(1);
            mWifiSsid.writeToParcel(dest, flags);
        } else {
            dest.writeInt(0);
        }
        dest.writeString(mBSSID);
        dest.writeString(mMacAddress);
        dest.writeInt(mMeteredHint ? 1 : 0);
        dest.writeInt(score);
        dest.writeDouble(txSuccessRate);
        dest.writeDouble(txRetriesRate);
        dest.writeDouble(txBadRate);
        dest.writeDouble(rxSuccessRate);
        dest.writeInt(badRssiCount);
        dest.writeInt(lowRssiCount);
        mSupplicantState.writeToParcel(dest, flags);