SoftApConfiguration.Builder


public static final class SoftApConfiguration.Builder
extends Object

java.lang.Object
   ↳ 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

Builder()

Constructs a Builder with default values (see Builder).

Public methods

SoftApConfiguration build()

Builds the SoftApConfiguration.

SoftApConfiguration.Builder setBssid(MacAddress bssid)

Specifies a BSSID for the AP.

SoftApConfiguration.Builder setChannels(SparseIntArray channels)

Specifies the channels and associated bands for the APs.

SoftApConfiguration.Builder setPassphrase(String passphrase, int securityType)

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.

Inherited methods

Public constructors

Builder

Added in API level 36
public Builder ()

Constructs a Builder with default values (see Builder).

Public methods

build

Added in API level 36
public SoftApConfiguration build ()

Builds the SoftApConfiguration.

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

setBssid

public SoftApConfiguration.Builder setBssid (MacAddress bssid)

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 ERROR(/#RANDOMIZATION_NONE). See ERROR(/#setMacRandomizationSetting(int)) for details. If multiple bands are requested via ERROR(/#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 ERROR(WifiManager.SoftApCallback.onCapabilityChanged(SoftApCapability)/android.net.wifi.WifiManager.SoftApCallback#onCapabilityChanged(android.net.wifi.SoftApCapability) WifiManager.SoftApCallback.onCapabilityChanged(SoftApCapability)) and ERROR(SoftApCapability.areFeaturesSupported(long)/android.net.wifi.SoftApCapability#areFeaturesSupported(long) SoftApCapability.areFeaturesSupported(long)) with ERROR(/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.

    Returns
    SoftApConfiguration.Builder Builder for chaining.

    Throws
    IllegalArgumentException when the given BSSID is the all-zero, multicast or broadcast MAC address.

    setChannels

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

    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 SoftApConfiguration.BAND_2GHZ with the special channel value 0 which has the framework auto-select from SoftApConfiguration.BAND_2GHZ.

    Parameters
    channels SparseIntArray: SparseIntArray (key: #BandType , value: channel) consists of BAND_ and corresponding channel. This value cannot be null.

    Returns
    SoftApConfiguration.Builder Builder for chaining. This value cannot be null.

    Throws
    IllegalArgumentException when more than 2 channels are set or the invalid channel or band type is configured.

    setPassphrase

    public SoftApConfiguration.Builder setPassphrase (String passphrase, 
                    int securityType)

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

    Parameters
    passphrase String: The passphrase to use for sepcific securityType configuration or null with SoftApConfiguration.SECURITY_TYPE_OPEN, SoftApConfiguration.SECURITY_TYPE_WPA3_OWE_TRANSITION, and SoftApConfiguration.SECURITY_TYPE_WPA3_OWE.

    securityType int: One of the following security types: SoftApConfiguration.SECURITY_TYPE_OPEN, SoftApConfiguration.SECURITY_TYPE_WPA2_PSK, SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION, SoftApConfiguration.SECURITY_TYPE_WPA3_SAE, SoftApConfiguration.SECURITY_TYPE_WPA3_OWE_TRANSITION, SoftApConfiguration.SECURITY_TYPE_WPA3_OWE. Value is SoftApConfiguration.SECURITY_TYPE_OPEN, SoftApConfiguration.SECURITY_TYPE_WPA2_PSK, SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION, SoftApConfiguration.SECURITY_TYPE_WPA3_SAE, SoftApConfiguration.SECURITY_TYPE_WPA3_OWE_TRANSITION, or SoftApConfiguration.SECURITY_TYPE_WPA3_OWE

    Returns
    SoftApConfiguration.Builder Builder for chaining. This value cannot be null.

    Throws
    IllegalArgumentException when the passphrase is non-null for - SoftApConfiguration.SECURITY_TYPE_OPEN - SoftApConfiguration.SECURITY_TYPE_WPA3_OWE_TRANSITION - SoftApConfiguration.SECURITY_TYPE_WPA3_OWE
    IllegalArgumentException when the passphrase is empty for - SoftApConfiguration.SECURITY_TYPE_WPA2_PSK, - SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION, - SoftApConfiguration.SECURITY_TYPE_WPA3_SAE,
    IllegalArgumentException before Build.VERSION_CODES.TIRAMISU) when the passphrase is not between 8 and 63 bytes (inclusive) for - SoftApConfiguration.SECURITY_TYPE_WPA2_PSK - SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION

    setWifiSsid

    public SoftApConfiguration.Builder setWifiSsid (WifiSsid wifiSsid)

    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.

    Returns
    SoftApConfiguration.Builder Builder for chaining.