WifiInfo
Stay organized with collections
Save and categorize content based on your preferences.
public
class
WifiInfo
extends Object
implements
Parcelable,
TransportInfo
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 |
Wifi
Builder for WifiInfo |
Constants | |
---|---|
String |
FREQUENCY_
Frequency in MHz |
String |
LINK_
The unit in which links speeds are expressed. |
int |
LINK_
Constant for unknown link speed. |
int |
SECURITY_
Security type for Easy Connect (DPP) network |
int |
SECURITY_
Security type for an EAP network. |
int |
SECURITY_
Security type for a WPA3-Enterprise network. |
int |
SECURITY_
Security type for a WPA3-Enterprise in 192-bit security network. |
int |
SECURITY_
Security type for an open network. |
int |
SECURITY_
Security type for an OSEN network. |
int |
SECURITY_
Security type for an OWE network. |
int |
SECURITY_
Security type for a Passpoint R1/R2 network, where TKIP and WEP are not allowed. |
int |
SECURITY_
Security type for a Passpoint R3 network, where TKIP and WEP are not allowed, and PMF must be set to Required. |
int |
SECURITY_
Security type for a PSK network. |
int |
SECURITY_
Security type for an SAE network. |
int |
SECURITY_
Unknown security type. |
int |
SECURITY_
Security type for a WAPI Certificate network. |
int |
SECURITY_
Security type for a WAPI PSK network. |
int |
SECURITY_
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<Mlo
|
get
Return the Multi-Link Operation (MLO) affiliated Links for Wi-Fi 7 access points. |
Mac
|
get
Return the Multi-Link Device (MLD) MAC Address for the connected access point. |
int
|
get
Return the access point Multi-Link Operation (MLO) link-id for Wi-Fi 7 access points. |
long
|
get
Returns a bitmask of all the applicable redactions (based on the permissions held by the receiving app) to be performed on this TransportInfo. |
List<Mlo
|
get
Return the associated Multi-Link Operation (MLO) Links for Wi-Fi 7 access points. |
String
|
get
Return the basic service set identifier (BSSID) of the current access point. |
int
|
get
Returns the security type of the current 802.11 network connection. |
static
Network
|
get
Map a supplicant state into a fine-grained network connectivity state. |
int
|
get
Returns the current frequency in |
boolean
|
get
|
List<Scan
|
get
Get all information elements found in the beacon of the connected bssid. |
int
|
get
This method was deprecated
in API level 31.
Use the methods on |
int
|
get
Returns the current link speed in |
String
|
get
Returns the MAC address used for this connection. |
int
|
get
Returns the maximum supported receive link speed in Mbps |
int
|
get
Returns the maximum supported transmit link speed in Mbps |
int
|
get
Each configured network has a unique small integer ID, used to identify the network. |
String
|
get
Returns the Fully Qualified Domain Name of the network if it is a Passpoint network. |
String
|
get
Returns the Provider Friendly Name of the network if it is a Passpoint network. |
String
|
get
Get the Passpoint unique identifier for the current connection |
int
|
get
Returns the received signal strength indicator of the current 802.11 network, in dBm. |
int
|
get
Returns the current receive link speed in Mbps. |
String
|
get
Returns the service set identifier (SSID) of the current 802.11 network. |
int
|
get
If this network is provisioned by a carrier, returns subscription Id corresponding to the associated SIM on the device. |
Supplicant
|
get
Return the detailed state of the supplicant's negotiation with an
access point, in the form of a |
int
|
get
Returns the current transmit link speed in Mbps. |
int
|
get
Get connection Wi-Fi standard |
int
|
hash
Returns a hash code value for the object. |
boolean
|
is
Returns true if the current Wifi network is a restricted network, false otherwise. |
Wifi
|
make
Create a copy of a |
String
|
to
Returns a string representation of the object. |
Inherited methods | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||
|
Constants
FREQUENCY_UNITS
public static final String FREQUENCY_UNITS
Frequency in MHz
Constant Value: "MHz"
LINK_SPEED_UNITS
public static final String LINK_SPEED_UNITS
The unit in which links speeds are expressed.
Constant Value: "Mbps"
LINK_SPEED_UNKNOWN
public static final int LINK_SPEED_UNKNOWN
Constant for unknown link speed.
Constant Value: -1 (0xffffffff)
SECURITY_TYPE_DPP
public static final int SECURITY_TYPE_DPP
Security type for Easy Connect (DPP) network
Constant Value: 13 (0x0000000d)
SECURITY_TYPE_EAP
public static final int SECURITY_TYPE_EAP
Security type for an EAP network.
Constant Value: 3 (0x00000003)
SECURITY_TYPE_EAP_WPA3_ENTERPRISE
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
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
public static final int SECURITY_TYPE_OPEN
Security type for an open network.
Constant Value: 0 (0x00000000)
SECURITY_TYPE_OSEN
public static final int SECURITY_TYPE_OSEN
Security type for an OSEN network.
Constant Value: 10 (0x0000000a)
SECURITY_TYPE_OWE
public static final int SECURITY_TYPE_OWE
Security type for an OWE network.
Constant Value: 6 (0x00000006)
SECURITY_TYPE_PASSPOINT_R1_R2
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
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
public static final int SECURITY_TYPE_PSK
Security type for a PSK network.
Constant Value: 2 (0x00000002)
SECURITY_TYPE_SAE
public static final int SECURITY_TYPE_SAE
Security type for an SAE network.
Constant Value: 4 (0x00000004)
SECURITY_TYPE_UNKNOWN
public static final int SECURITY_TYPE_UNKNOWN
Unknown security type.
Constant Value: -1 (0xffffffff)
SECURITY_TYPE_WAPI_CERT
public static final int SECURITY_TYPE_WAPI_CERT
Security type for a WAPI Certificate network.
Constant Value: 8 (0x00000008)
SECURITY_TYPE_WAPI_PSK
public static final int SECURITY_TYPE_WAPI_PSK
Security type for a WAPI PSK network.
Constant Value: 7 (0x00000007)
SECURITY_TYPE_WEP
public static final int SECURITY_TYPE_WEP
Security type for a WEP network.
Constant Value: 1 (0x00000001)
Public methods
equals
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 returntrue
. - It is symmetric: for any non-null reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any non-null reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any non-null reference values
x
andy
, multiple invocations ofx.equals(y)
consistently returntrue
or consistently returnfalse
, provided no information used inequals
comparisons on the objects is modified. - For any non-null reference value
x
,x.equals(null)
should returnfalse
.
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
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.
getApMldMacAddress
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:
getWifiStandard()
returns ScanResult.WIFI_STANDARD_11BE
.
Returns | |
---|---|
Mac |
the MLD Mac address |
getApMloLinkId
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 |
Mlo or a valid value (0-15).
Value is between MloLink.INVALID_MLO_LINK_ID and MloLink.MAX_MLO_LINK_ID inclusive |
getApplicableRedactions
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
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.
getBSSID
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
public int getCurrentSecurityType ()
Returns the security type of the current 802.11 network connection.
Returns | |
---|---|
int |
the security type, or SECURITY_ if not currently connected.
Value is SECURITY_ , SECURITY_ , SECURITY_ , SECURITY_ , SECURITY_ , SECURITY_ , SECURITY_ , SECURITY_ , SECURITY_ , SECURITY_ , SECURITY_ , SECURITY_ , SECURITY_ , or SECURITY_ |
getDetailedStateOf
public static NetworkInfo.DetailedState getDetailedStateOf (SupplicantState suppState)
Map a supplicant state into a fine-grained network connectivity state.
Parameters | |
---|---|
supp |
Supplicant : the supplicant state |
Returns | |
---|---|
Network |
the corresponding Detailed |
getFrequency
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
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
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<Scan |
List of information elements Scan or null. |
getIpAddress
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
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_ if link speed is unknown. |
See also:
getMacAddress
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. and
Manifest. . |
getMaxSupportedRxLinkSpeedMbps
public int getMaxSupportedRxLinkSpeedMbps ()
Returns the maximum supported receive link speed in Mbps
Returns | |
---|---|
int |
the max supported Rx link speed or LINK_ if link speed is
unknown. @see #LINK_SPEED_UNKNOWN |
getMaxSupportedTxLinkSpeedMbps
public int getMaxSupportedTxLinkSpeedMbps ()
Returns the maximum supported transmit link speed in Mbps
Returns | |
---|---|
int |
the max supported tx link speed or LINK_ if link speed is
unknown. @see #LINK_SPEED_UNKNOWN |
getNetworkId
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
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
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
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
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
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_ if link speed is unknown.
Value is -1 or greater |
See also:
getSSID
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
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
public SupplicantState getSupplicantState ()
Return the detailed state of the supplicant's negotiation with an
access point, in the form of a SupplicantState
object.
Returns | |
---|---|
Supplicant |
the current Supplicant |
getTxLinkSpeedMbps
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_ if link speed is unknown.
Value is -1 or greater |
See also:
getWifiStandard
public int getWifiStandard ()
Get connection Wi-Fi standard
Returns | |
---|---|
int |
the connection Wi-Fi standard
Value is Scan , Scan , Scan , Scan , Scan , Scan , or Scan |
hashCode
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 inequals
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 thehashCode
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 thehashCode
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
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
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 | |
---|---|
Wifi |
Copy of this instance with the necessary redactions.
This value cannot be null . |
toString
public String toString ()
Returns a string representation of the object.
Returns | |
---|---|
String |
a string representation of the object. |