Added in API level 36

Builder


class Builder
kotlin.Any
   ↳ android.net.wifi.SoftApConfiguration.Builder

Builds a SoftApConfiguration, which allows an app to configure various aspects of a Soft AP. All fields are optional. By default, SSID and BSSID are automatically chosen by the framework, and an open network is created.

Summary

Public constructors

Constructs a Builder with default values (see Builder).

Public methods
SoftApConfiguration

Builds the SoftApConfiguration.

SoftApConfiguration.Builder

Specifies a BSSID for the AP.

SoftApConfiguration.Builder

Specifies the channels and associated bands for the APs.

SoftApConfiguration.Builder
setPassphrase(passphrase: String?, securityType: Int)

Specifies that this AP should use specific security type with the given ASCII passphrase.

SoftApConfiguration.Builder
setWifiSsid(wifiSsid: WifiSsid?)

Specifies an SSID for the AP in the form of WifiSsid.

Public constructors

Builder

Added in API level 36
Builder()

Constructs a Builder with default values (see Builder).

Public methods

build

Added in API level 36
fun build(): SoftApConfiguration

Builds the SoftApConfiguration.

Return
SoftApConfiguration A new SoftApConfiguration, as configured by previous method calls. This value cannot be null.

setBssid

fun setBssid(bssid: MacAddress?): SoftApConfiguration.Builder

Specifies a BSSID for the AP.

  • If not set, defaults to null.
  • When this method is called, the caller needs to configure MAC randomization settings to #RANDOMIZATION_NONE. See #setMacRandomizationSetting(int) for details. If multiple bands are requested via #setBands(int[]) or setChannels(android.util.SparseIntArray), HAL will derive 2 MAC addresses since framework only sends down 1 MAC address. An example (but different implementation may perform a different mapping):
  • MAC address 1: copy value of MAC address, and set byte 1 = (0xFF - BSSID[1])
  • MAC address 2: copy value of MAC address, and set byte 2 = (0xFF - BSSID[2])
  • Example BSSID argument: e2:38:60:c4:0e:b7 Derived MAC address 1: e2:c7:60:c4:0e:b7 Derived MAC address 2: e2:38:9f:c4:0e:b7

    Use android.net.wifi.WifiManager.SoftApCallback#onCapabilityChanged(android.net.wifi.SoftApCapability) and SoftApCapability.areFeaturesSupported(long) with SoftApCapability.SOFTAP_FEATURE_MAC_ADDRESS_CUSTOMIZATION to determine whether or not this feature is supported.

    Callers without the listed permissions will not be able to start SoftAP with a non-null BSSID. DO and Carrier apps starting SoftAp with TetheringManager.startTethering are exempted from this permission restriction.

    Parameters
    bssid MacAddress?: BSSID, or null to have the BSSID chosen by the framework. The caller is responsible for avoiding collisions.
    Return
    SoftApConfiguration.Builder Builder for chaining.
    Exceptions
    java.lang.IllegalArgumentException when the given BSSID is the all-zero, multicast or broadcast MAC address.

    setChannels

    Added in API level 36
    fun setChannels(channels: SparseIntArray): SoftApConfiguration.Builder

    Specifies the channels and associated bands for the APs.

    The API contains (band, channel) input since the 6GHz band uses the same channel numbering scheme as is used in the 2.4GHz and 5GHz band. Therefore, both are needed to uniquely identify individual channels.

    Reference the Wi-Fi channel numbering and the channelization in IEEE 802.11-2016 specifications, section 17.3.8.4.2, 17.3.8.4.3 and Table 15-6.

    Using the special value 0 which has the framework auto-select a valid channel from the band configured. When more than 1 channel/band is set, this will bring up concurrent APs on the requested channels and bands (if possible). Use WifiManager.isBridgedApConcurrencySupported() to determine whether concurrent APs are supported. If not set, the default value is BAND_2GHZ with the special channel value 0 which has the framework auto-select from BAND_2GHZ.

    Parameters
    channels SparseIntArray: SparseIntArray (key: BandType , value: channel) consists of BAND_ and corresponding channel. This value cannot be null.
    Return
    SoftApConfiguration.Builder Builder for chaining. This value cannot be null.
    Exceptions
    java.lang.IllegalArgumentException when more than 2 channels are set or the invalid channel or band type is configured.

    setPassphrase

    fun setPassphrase(
        passphrase: String?,
        securityType: Int
    ): SoftApConfiguration.Builder

    Specifies that this AP should use specific security type with the given ASCII passphrase.

    Parameters
    securityType Int: One of the following security types: SECURITY_TYPE_OPEN, SECURITY_TYPE_WPA2_PSK, SECURITY_TYPE_WPA3_SAE_TRANSITION, SECURITY_TYPE_WPA3_SAE, SECURITY_TYPE_WPA3_OWE_TRANSITION, SECURITY_TYPE_WPA3_OWE. Value is android.net.wifi.SoftApConfiguration#SECURITY_TYPE_OPEN, android.net.wifi.SoftApConfiguration#SECURITY_TYPE_WPA2_PSK, android.net.wifi.SoftApConfiguration#SECURITY_TYPE_WPA3_SAE_TRANSITION, android.net.wifi.SoftApConfiguration#SECURITY_TYPE_WPA3_SAE, android.net.wifi.SoftApConfiguration#SECURITY_TYPE_WPA3_OWE_TRANSITION, or android.net.wifi.SoftApConfiguration#SECURITY_TYPE_WPA3_OWE
    passphrase String?: The passphrase to use for sepcific securityType configuration or null with SECURITY_TYPE_OPEN, SECURITY_TYPE_WPA3_OWE_TRANSITION, and SECURITY_TYPE_WPA3_OWE.
    Return
    SoftApConfiguration.Builder Builder for chaining. This value cannot be null.
    Exceptions
    java.lang.IllegalArgumentException before android.os.Build.VERSION_CODES#TIRAMISU) when the passphrase is not between 8 and 63 bytes (inclusive) for - SECURITY_TYPE_WPA2_PSK - SECURITY_TYPE_WPA3_SAE_TRANSITION

    setWifiSsid

    fun setWifiSsid(wifiSsid: WifiSsid?): SoftApConfiguration.Builder

    Specifies an SSID for the AP in the form of WifiSsid.

    Null SSID only support when configure a local-only hotspot.

  • If not set, defaults to null.
  • Parameters
    wifiSsid WifiSsid?: SSID, or null ot have the SSID automatically chosen by the framework.
    Return
    SoftApConfiguration.Builder Builder for chaining.