WifiInfo


public class WifiInfo
extends Object implements TransportInfo, Parcelable

java.lang.Object
   ↳ android.net.wifi.WifiInfo


Describes the state of any Wi-Fi connection that is active or is in the process of being set up. In the connected state, access to location sensitive fields requires the same permissions as WifiManager#getScanResults. If such access is not allowed, getSSID() will return WifiManager#UNKNOWN_SSID and getBSSID() will return "02:00:00:00:00:00". getApMldMacAddress() will return null. getNetworkId() will return -1. getPasspointFqdn() will return null. getPasspointProviderFriendlyName() will return null. getInformationElements() will return null. getMacAddress() will return "02:00:00:00:00:00".

Summary

Nested classes

class WifiInfo.Builder

Builder for WifiInfo 

Constants

String FREQUENCY_UNITS

Frequency in MHz

String LINK_SPEED_UNITS

The unit in which links speeds are expressed.

int LINK_SPEED_UNKNOWN

Constant for unknown link speed.

int SECURITY_TYPE_DPP

Security type for Easy Connect (DPP) network

int SECURITY_TYPE_EAP

Security type for an EAP network.

int SECURITY_TYPE_EAP_WPA3_ENTERPRISE

Security type for a WPA3-Enterprise network.

int SECURITY_TYPE_EAP_WPA3_ENTERPRISE_192_BIT

Security type for a WPA3-Enterprise in 192-bit security network.

int SECURITY_TYPE_OPEN

Security type for an open network.

int SECURITY_TYPE_OSEN

Security type for an OSEN network.

int SECURITY_TYPE_OWE

Security type for an OWE network.

int SECURITY_TYPE_PASSPOINT_R1_R2

Security type for a Passpoint R1/R2 network, where TKIP and WEP are not allowed.

int SECURITY_TYPE_PASSPOINT_R3

Security type for a Passpoint R3 network, where TKIP and WEP are not allowed, and PMF must be set to Required.

int SECURITY_TYPE_PSK

Security type for a PSK network.

int SECURITY_TYPE_SAE

Security type for an SAE network.

int SECURITY_TYPE_UNKNOWN

Unknown security type.

int SECURITY_TYPE_WAPI_CERT

Security type for a WAPI Certificate network.

int SECURITY_TYPE_WAPI_PSK

Security type for a WAPI PSK network.

int SECURITY_TYPE_WEP

Security type for a WEP network.

Inherited constants

Public methods

boolean equals(Object that)

Indicates whether some other object is "equal to" this one.

List<MloLink> getAffiliatedMloLinks()

Return the Multi-Link Operation (MLO) affiliated Links for Wi-Fi 7 access points.

MacAddress getApMldMacAddress()

Return the Multi-Link Device (MLD) MAC Address for the connected access point.

int getApMloLinkId()

Return the access point Multi-Link Operation (MLO) link-id for Wi-Fi 7 access points.

long getApplicableRedactions()

Returns a bitmask of all the applicable redactions (based on the permissions held by the receiving app) to be performed on this TransportInfo.

List<MloLink> getAssociatedMloLinks()

Return the associated Multi-Link Operation (MLO) Links for Wi-Fi 7 access points.

String getBSSID()

Return the basic service set identifier (BSSID) of the current access point.

int getCurrentSecurityType()

Returns the security type of the current 802.11 network connection.

static NetworkInfo.DetailedState getDetailedStateOf(SupplicantState suppState)

Map a supplicant state into a fine-grained network connectivity state.

int getFrequency()

Returns the current frequency in FREQUENCY_UNITS.

boolean getHiddenSSID()
List<ScanResult.InformationElement> getInformationElements()

Get all information elements found in the beacon of the connected bssid.

int getIpAddress()

This method was deprecated in API level 31. Use the methods on LinkProperties which can be obtained either via NetworkCallback#onLinkPropertiesChanged(Network, LinkProperties) or ConnectivityManager#getLinkProperties(Network).

int getLinkSpeed()

Returns the current link speed in LINK_SPEED_UNITS.

String getMacAddress()

Returns the MAC address used for this connection.

int getMaxSupportedRxLinkSpeedMbps()

Returns the maximum supported receive link speed in Mbps

int getMaxSupportedTxLinkSpeedMbps()

Returns the maximum supported transmit link speed in Mbps

int getNetworkId()

Each configured network has a unique small integer ID, used to identify the network.

String getPasspointFqdn()

Returns the Fully Qualified Domain Name of the network if it is a Passpoint network.

String getPasspointProviderFriendlyName()

Returns the Provider Friendly Name of the network if it is a Passpoint network.

String getPasspointUniqueId()

Get the Passpoint unique identifier for the current connection

int getRssi()

Returns the received signal strength indicator of the current 802.11 network, in dBm.

int getRxLinkSpeedMbps()

Returns the current receive link speed in Mbps.

String getSSID()

Returns the service set identifier (SSID) of the current 802.11 network.

int getSubscriptionId()

If this network is provisioned by a carrier, returns subscription Id corresponding to the associated SIM on the device.

SupplicantState getSupplicantState()

Return the detailed state of the supplicant's negotiation with an access point, in the form of a SupplicantState object.

int getTxLinkSpeedMbps()

Returns the current transmit link speed in Mbps.

int getWifiStandard()

Get connection Wi-Fi standard

int hashCode()

Returns a hash code value for the object.

boolean isRestricted()

Returns true if the current Wifi network is a restricted network, false otherwise.

WifiInfo makeCopy(long redactions)

Create a copy of a WifiInfo with some fields redacted based on the permissions held by the receiving app.

String toString()

Returns a string representation of the object.

Inherited methods

Constants

FREQUENCY_UNITS

Added in API level 21
public static final String FREQUENCY_UNITS

Frequency in MHz

Constant Value: "MHz"

Added in API level 1
public static final String LINK_SPEED_UNITS

The unit in which links speeds are expressed.

Constant Value: "Mbps"

Added in API level 29
public static final int LINK_SPEED_UNKNOWN

Constant for unknown link speed.

Constant Value: -1 (0xffffffff)

SECURITY_TYPE_DPP

Added in API level 33
public static final int SECURITY_TYPE_DPP

Security type for Easy Connect (DPP) network

Constant Value: 13 (0x0000000d)

SECURITY_TYPE_EAP

Added in API level 31
public static final int SECURITY_TYPE_EAP

Security type for an EAP network.

Constant Value: 3 (0x00000003)

SECURITY_TYPE_EAP_WPA3_ENTERPRISE

Added in API level 31
public static final int SECURITY_TYPE_EAP_WPA3_ENTERPRISE

Security type for a WPA3-Enterprise network.

Constant Value: 9 (0x00000009)

SECURITY_TYPE_EAP_WPA3_ENTERPRISE_192_BIT

Added in API level 31
public static final int SECURITY_TYPE_EAP_WPA3_ENTERPRISE_192_BIT

Security type for a WPA3-Enterprise in 192-bit security network.

Constant Value: 5 (0x00000005)

SECURITY_TYPE_OPEN

Added in API level 31
public static final int SECURITY_TYPE_OPEN

Security type for an open network.

Constant Value: 0 (0x00000000)

SECURITY_TYPE_OSEN

Added in API level 31
public static final int SECURITY_TYPE_OSEN

Security type for an OSEN network.

Constant Value: 10 (0x0000000a)

SECURITY_TYPE_OWE

Added in API level 31
public static final int SECURITY_TYPE_OWE

Security type for an OWE network.

Constant Value: 6 (0x00000006)

SECURITY_TYPE_PASSPOINT_R1_R2

Added in API level 31
public static final int SECURITY_TYPE_PASSPOINT_R1_R2

Security type for a Passpoint R1/R2 network, where TKIP and WEP are not allowed.

Constant Value: 11 (0x0000000b)

SECURITY_TYPE_PASSPOINT_R3

Added in API level 31
public static final int SECURITY_TYPE_PASSPOINT_R3

Security type for a Passpoint R3 network, where TKIP and WEP are not allowed, and PMF must be set to Required.

Constant Value: 12 (0x0000000c)

SECURITY_TYPE_PSK

Added in API level 31
public static final int SECURITY_TYPE_PSK

Security type for a PSK network.

Constant Value: 2 (0x00000002)

SECURITY_TYPE_SAE

Added in API level 31
public static final int SECURITY_TYPE_SAE

Security type for an SAE network.

Constant Value: 4 (0x00000004)

SECURITY_TYPE_UNKNOWN

Added in API level 31
public static final int SECURITY_TYPE_UNKNOWN

Unknown security type.

Constant Value: -1 (0xffffffff)

SECURITY_TYPE_WAPI_CERT

Added in API level 31
public static final int SECURITY_TYPE_WAPI_CERT

Security type for a WAPI Certificate network.

Constant Value: 8 (0x00000008)

SECURITY_TYPE_WAPI_PSK

Added in API level 31
public static final int SECURITY_TYPE_WAPI_PSK

Security type for a WAPI PSK network.

Constant Value: 7 (0x00000007)

SECURITY_TYPE_WEP

Added in API level 31
public static final int SECURITY_TYPE_WEP

Security type for a WEP network.

Constant Value: 1 (0x00000001)

Public methods

equals

Added in API level 1
public boolean equals (Object that)

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
that Object: the reference object with which to compare.

Returns
boolean true if this object is the same as the obj argument; false otherwise.

getAffiliatedMloLinks

Added in API level 33
public List<MloLink> getAffiliatedMloLinks ()

Return the Multi-Link Operation (MLO) affiliated Links for Wi-Fi 7 access points. i.e. when getWifiStandard() returns ScanResult#WIFI_STANDARD_11BE. Affiliated links are the links supported by the Access Point Multi Link Device (AP MLD). The Station Multi Link Device (STA MLD) gathers affiliated link information from scan results. Depending on Station's capability, it associates to all or a subset of affiliated links.

Note:getAssociatedMloLinks() returns associated links.

Returns
List<MloLink> List of affiliated MLO links, or an empty list if access point is not Wi-Fi 7 This value cannot be null.

getApMldMacAddress

Added in API level 33
public MacAddress getApMldMacAddress ()

Return the Multi-Link Device (MLD) MAC Address for the connected access point.

The returned MLD MAC Address will be null in the following cases: There is no network currently connected The connected access point is not an MLD access point, i.e. getWifiStandard() returns ScanResult#WIFI_STANDARD_11BE. The caller has insufficient permissions to access the access point MLD MAC Address.

Returns
MacAddress the MLD Mac address

getApMloLinkId

Added in API level 33
public int getApMloLinkId ()

Return the access point Multi-Link Operation (MLO) link-id for Wi-Fi 7 access points. i.e. getWifiStandard() returns ScanResult#WIFI_STANDARD_11BE, otherwise return MloLink#INVALID_MLO_LINK_ID. Valid values are 0-15 as described in IEEE 802.11be Specification, section 9.4.2.295b.2.

Returns
int MloLink#INVALID_MLO_LINK_ID or a valid value (0-15). Value is between MloLink.INVALID_MLO_LINK_ID and MloLink.MAX_MLO_LINK_ID inclusive

getApplicableRedactions

Added in API level 31
public long getApplicableRedactions ()

Returns a bitmask of all the applicable redactions (based on the permissions held by the receiving app) to be performed on this TransportInfo.

Returns
long bitmask of redactions applicable on this instance.

getAssociatedMloLinks

Added in API level 34
public List<MloLink> getAssociatedMloLinks ()

Return the associated Multi-Link Operation (MLO) Links for Wi-Fi 7 access points. i.e. when getWifiStandard() returns ScanResult#WIFI_STANDARD_11BE. Affiliated links are the links supported by the Access Point Multi Link Device (AP MLD). The Station Multi Link Device (STA MLD) gathers affiliated link information from scan results. Depending on Station's capability, it associates to all or a subset of affiliated links.

Note:getAffiliatedMloLinks() returns affiliated links.

Returns
List<MloLink> List of associated MLO links, or an empty list if access point is not a multi-link device. This value cannot be null.

getBSSID

Added in API level 1
public String getBSSID ()

Return the basic service set identifier (BSSID) of the current access point. In case of Multi Link Operation (MLO), the BSSID corresponds to the BSSID of the link used for association.

The BSSID may be null, if there is no network currently connected. "02:00:00:00:00:00", if the caller has insufficient permissions to access the BSSID.

Returns
String the BSSID, in the form of a six-byte MAC address: XX:XX:XX:XX:XX:XX

getCurrentSecurityType

Added in API level 31
public int getCurrentSecurityType ()

Returns the security type of the current 802.11 network connection.

Returns
int the security type, or SECURITY_TYPE_UNKNOWN if not currently connected. Value is SECURITY_TYPE_UNKNOWN, SECURITY_TYPE_OPEN, SECURITY_TYPE_WEP, SECURITY_TYPE_PSK, SECURITY_TYPE_EAP, SECURITY_TYPE_SAE, SECURITY_TYPE_OWE, SECURITY_TYPE_WAPI_PSK, SECURITY_TYPE_WAPI_CERT, SECURITY_TYPE_EAP_WPA3_ENTERPRISE, SECURITY_TYPE_EAP_WPA3_ENTERPRISE_192_BIT, SECURITY_TYPE_PASSPOINT_R1_R2, SECURITY_TYPE_PASSPOINT_R3, or SECURITY_TYPE_DPP

getDetailedStateOf

Added in API level 1
public static NetworkInfo.DetailedState getDetailedStateOf (SupplicantState suppState)

Map a supplicant state into a fine-grained network connectivity state.

Parameters
suppState SupplicantState: the supplicant state

Returns
NetworkInfo.DetailedState the corresponding DetailedState

getFrequency

Added in API level 21
public int getFrequency ()

Returns the current frequency in FREQUENCY_UNITS. In case of Multi Link Operation (MLO), returned value is the frequency of the associated link with the highest RSSI.

Returns
int the frequency.

See also:

getHiddenSSID

Added in API level 1
public boolean getHiddenSSID ()

Returns
boolean true if this network does not broadcast its SSID, so an SSID-specific probe request must be used for scans.

getInformationElements

Added in API level 31
public List<ScanResult.InformationElement> getInformationElements ()

Get all information elements found in the beacon of the connected bssid.

The information elements will be null if there is no network currently connected or if the caller has insufficient permissions to access the info elements.

Returns
List<ScanResult.InformationElement> List of information elements ScanResult.InformationElement or null.

getIpAddress

Added in API level 1
Deprecated in API level 31
public int getIpAddress ()

This method was deprecated in API level 31.
Use the methods on LinkProperties which can be obtained either via NetworkCallback#onLinkPropertiesChanged(Network, LinkProperties) or ConnectivityManager#getLinkProperties(Network).

Returns
int

getLinkSpeed

Added in API level 1
public int getLinkSpeed ()

Returns the current link speed in LINK_SPEED_UNITS. In case of Multi Link Operation (MLO), returned value is the current link speed of the associated link with the highest RSSI.

Returns
int the link speed or LINK_SPEED_UNKNOWN if link speed is unknown.

getMacAddress

Added in API level 1
public String getMacAddress ()

Returns the MAC address used for this connection. In case of Multi Link Operation (MLO), returned value is the Station MLD MAC address.

Returns
String MAC address of the connection or "02:00:00:00:00:00" if the caller has insufficient permission. Requires android.Manifest.permission#LOCAL_MAC_ADDRESS and Manifest.permission.ACCESS_FINE_LOCATION.

getMaxSupportedRxLinkSpeedMbps

Added in API level 30
public int getMaxSupportedRxLinkSpeedMbps ()

Returns the maximum supported receive link speed in Mbps

Returns
int the max supported Rx link speed or LINK_SPEED_UNKNOWN if link speed is unknown. @see #LINK_SPEED_UNKNOWN

getMaxSupportedTxLinkSpeedMbps

Added in API level 30
public int getMaxSupportedTxLinkSpeedMbps ()

Returns the maximum supported transmit link speed in Mbps

Returns
int the max supported tx link speed or LINK_SPEED_UNKNOWN if link speed is unknown. @see #LINK_SPEED_UNKNOWN

getNetworkId

Added in API level 1
public int getNetworkId ()

Each configured network has a unique small integer ID, used to identify the network. This method returns the ID for the currently connected network.

The networkId may be -1 if there is no currently connected network or if the caller has insufficient permissions to access the network ID.

Returns
int the network ID.

getPasspointFqdn

Added in API level 29
public String getPasspointFqdn ()

Returns the Fully Qualified Domain Name of the network if it is a Passpoint network.

The FQDN may be null if no network currently connected, currently connected network is not passpoint network or the caller has insufficient permissions to access the FQDN.

Returns
String

getPasspointProviderFriendlyName

Added in API level 29
public String getPasspointProviderFriendlyName ()

Returns the Provider Friendly Name of the network if it is a Passpoint network.

The Provider Friendly Name may be null if no network currently connected, currently connected network is not passpoint network or the caller has insufficient permissions to access the Provider Friendly Name.

Returns
String

getPasspointUniqueId

Added in API level 35
public String getPasspointUniqueId ()

Get the Passpoint unique identifier for the current connection

Returns
String Passpoint unique identifier, or null if this connection is not Passpoint.

getRssi

Added in API level 1
public int getRssi ()

Returns the received signal strength indicator of the current 802.11 network, in dBm. In case of Multi Link Operation (MLO), returned RSSI is the highest of all associated links.

Use WifiManager.calculateSignalLevel(int) to convert this number into an absolute signal level which can be displayed to a user.

Returns
int the RSSI.

getRxLinkSpeedMbps

Added in API level 29
public int getRxLinkSpeedMbps ()

Returns the current receive link speed in Mbps. In case of Multi Link Operation (MLO), returned value is the receive link speed of the associated link with the highest RSSI.

Returns
int the Rx link speed or LINK_SPEED_UNKNOWN if link speed is unknown. Value is -1 or greater

See also:

getSSID

Added in API level 1
public String getSSID ()

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 WifiManager#UNKNOWN_SSID, if there is no network currently connected or if the caller has insufficient permissions to access the SSID.

Prior to Build.VERSION_CODES.JELLY_BEAN_MR1, this method always returned the SSID with no quotes around it.

Returns
String the SSID.

getSubscriptionId

Added in API level 31
public int getSubscriptionId ()

If this network is provisioned by a carrier, returns subscription Id corresponding to the associated SIM on the device. If this network is not provisioned by a carrier, returns SubscriptionManager.INVALID_SUBSCRIPTION_ID

Returns
int

getSupplicantState

Added in API level 1
public SupplicantState getSupplicantState ()

Return the detailed state of the supplicant's negotiation with an access point, in the form of a SupplicantState object.

Returns
SupplicantState the current SupplicantState

getTxLinkSpeedMbps

Added in API level 29
public int getTxLinkSpeedMbps ()

Returns the current transmit link speed in Mbps. In case of Multi Link Operation (MLO), returned value is the current transmit link speed of the associated link with the highest RSSI.

Returns
int the Tx link speed or LINK_SPEED_UNKNOWN if link speed is unknown. Value is -1 or greater

See also:

getWifiStandard

Added in API level 30
public int getWifiStandard ()

Get connection Wi-Fi standard

Returns
int the connection Wi-Fi standard Value is ScanResult.WIFI_STANDARD_UNKNOWN, ScanResult.WIFI_STANDARD_LEGACY, ScanResult.WIFI_STANDARD_11N, ScanResult.WIFI_STANDARD_11AC, ScanResult.WIFI_STANDARD_11AX, ScanResult.WIFI_STANDARD_11AD, or ScanResult.WIFI_STANDARD_11BE

hashCode

Added in API level 1
public int hashCode ()

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

Returns
int a hash code value for this object.

isRestricted

Added in API level 33
public boolean isRestricted ()

Returns true if the current Wifi network is a restricted network, false otherwise. A restricted network has its NetworkCapabilities#NET_CAPABILITY_NOT_RESTRICTED capability removed.

Returns
boolean

makeCopy

Added in API level 31
public WifiInfo makeCopy (long redactions)

Create a copy of a WifiInfo with some fields redacted based on the permissions held by the receiving app.

Parameters
redactions long: bitmask of redactions that needs to be performed on this instance.

Returns
WifiInfo Copy of this instance with the necessary redactions. This value cannot be null.

toString

Added in API level 1
public String toString ()

Returns a string representation of the object.

Returns
String a string representation of the object.