Builder
class Builder
kotlin.Any | |
↳ | android.net.wifi.aware.WifiAwareNetworkSpecifier.Builder |
A builder class for a Wi-Fi Aware network specifier to set up an Aware connection with a peer.
Summary
Public constructors | |
---|---|
Builder(discoverySession: DiscoverySession, peerHandle: PeerHandle) Create a builder for |
|
Builder(publishDiscoverySession: PublishDiscoverySession) Create a builder for |
Public methods | |
---|---|
WifiAwareNetworkSpecifier |
build() Create a |
WifiAwareNetworkSpecifier.Builder |
setChannelFrequencyMhz(channelInMhz: Int, required: Boolean) Configure the Channel frequency for the Wi-Fi Aware connection being requested. |
WifiAwareNetworkSpecifier.Builder |
setDataPathSecurityConfig(securityConfig: WifiAwareDataPathSecurityConfig) Configure security config for the Wi-Fi Aware connection being requested. |
WifiAwareNetworkSpecifier.Builder |
Configure the PMK for the Wi-Fi Aware connection being requested. |
WifiAwareNetworkSpecifier.Builder |
Configure the port number which will be used to create a connection over this link. |
WifiAwareNetworkSpecifier.Builder |
setPskPassphrase(pskPassphrase: String) Configure the PSK Passphrase for the Wi-Fi Aware connection being requested. |
WifiAwareNetworkSpecifier.Builder |
setTransportProtocol(transportProtocol: Int) Configure the transport protocol which will be used to create a connection over this link. |
Public constructors
Builder
Builder(
discoverySession: DiscoverySession,
peerHandle: PeerHandle)
Create a builder for WifiAwareNetworkSpecifier
used in requests to set up a Wi-Fi Aware connection with a specific peer.
To set up a connection to any peer or to multiple peers use Builder(android.net.wifi.aware.PublishDiscoverySession)
.
Parameters | |
---|---|
discoverySession |
DiscoverySession: A Wi-Fi Aware discovery session in whose context the connection is created. This value cannot be null . |
peerHandle |
PeerHandle: The handle of the peer to which the Wi-Fi Aware connection is requested. The peer is discovered through Wi-Fi Aware discovery. The handle can be obtained through DiscoverySessionCallback#onServiceDiscovered(PeerHandle, byte[], java.util.List) or DiscoverySessionCallback#onMessageReceived(PeerHandle, byte[]) . This value cannot be null . |
Builder
Builder(publishDiscoverySession: PublishDiscoverySession)
Create a builder for WifiAwareNetworkSpecifier
used in requests to set up a Wi-Fi Aware connection. This configuration allows connections to any peers or to multiple peers (as opposed to only a specific peer with Builder(android.net.wifi.aware.DiscoverySession,android.net.wifi.aware.PeerHandle)
).
Multiple connections can be triggered by this configuration and using a single request via ConnectivityManager#requestNetwork(NetworkRequest, ConnectivityManager.NetworkCallback)
and similar methods. Each successful connection will be signaled via the standard Connectivity Manager mechanisms - ConnectivityManager.NetworkCallback#onAvailable(Network)
. Calling ConnectivityManager#unregisterNetworkCallback(ConnectivityManager.NetworkCallback)
will terminate all connections.
Parameters | |
---|---|
publishDiscoverySession |
PublishDiscoverySession: This value cannot be null . |
Public methods
build
fun build(): WifiAwareNetworkSpecifier
Create a android.net.NetworkRequest.Builder#setNetworkSpecifier(NetworkSpecifier)
for a WiFi Aware connection (link) to the specified peer. The android.net.NetworkRequest.Builder#addTransportType(int)
should be set to android.net.NetworkCapabilities#TRANSPORT_WIFI_AWARE
.
The default builder constructor will initialize a NetworkSpecifier which requests an open (non-encrypted) link. To request an encrypted link use the setPskPassphrase(java.lang.String)
or setPmk(byte[])
builder methods.
Return | |
---|---|
WifiAwareNetworkSpecifier |
A NetworkSpecifier to be used to construct android.net.NetworkRequest.Builder#setNetworkSpecifier(NetworkSpecifier) to pass to android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest, * android.net.ConnectivityManager.NetworkCallback) [or other varieties of that API]. This value cannot be null . |
setChannelFrequencyMhz
fun setChannelFrequencyMhz(
channelInMhz: Int,
required: Boolean
): WifiAwareNetworkSpecifier.Builder
Configure the Channel frequency for the Wi-Fi Aware connection being requested. This method is optional - if not called, then channelInMhz to use will be decided by firmware. Only use this when WifiAwareManager#isSetChannelOnDataPathSupported()
is true, otherwise the set channelInMhz will be ignored.
Parameters | |
---|---|
channelInMhz |
Int: Channel frequency in Mhz. Value is 0 or greater |
required |
Boolean: If set to true, Channel request is specified and must be respected. If the firmware cannot honor the request then the data-path request is rejected. Otherwise, requested channelInMhz is a recommendation and may be overridden by the firmware. |
Return | |
---|---|
WifiAwareNetworkSpecifier.Builder |
the current Builder builder, enabling chaining of builder methods. This value cannot be null . |
setDataPathSecurityConfig
fun setDataPathSecurityConfig(securityConfig: WifiAwareDataPathSecurityConfig): WifiAwareNetworkSpecifier.Builder
Configure security config for the Wi-Fi Aware connection being requested. This method is optional - if not called, then an Open (unencrypted) connection will be created. Note: this method is the superset of the setPmk(byte[])
and setPskPassphrase(java.lang.String)
.
Parameters | |
---|---|
securityConfig |
WifiAwareDataPathSecurityConfig: The (optional) security config to be used to encrypt the link. This value cannot be null . |
Return | |
---|---|
WifiAwareNetworkSpecifier.Builder |
the current Builder builder, enabling chaining of builder methods. This value cannot be null . |
setPmk
fun setPmk(pmk: ByteArray): WifiAwareNetworkSpecifier.Builder
Configure the PMK for the Wi-Fi Aware connection being requested. This method is optional - if not called, then an Open (unencrypted) connection will be created. Note: Use setDataPathSecurityConfig(android.net.wifi.aware.WifiAwareDataPathSecurityConfig)
to avoid interoperability issues when devices support different cipher suites by explicitly specifying a cipher suite as opposed to relying on a default cipher suite.
Parameters | |
---|---|
pmk |
ByteArray: A PMK (pairwise master key, see IEEE 802.11i) specifying the key to use for encrypting the data-path. Use the setPskPassphrase(java.lang.String) to specify a Passphrase. This value cannot be null . |
Return | |
---|---|
WifiAwareNetworkSpecifier.Builder |
the current Builder builder, enabling chaining of builder methods. This value cannot be null . |
setPort
fun setPort(port: Int): WifiAwareNetworkSpecifier.Builder
Configure the port number which will be used to create a connection over this link. This configuration should only be done on the server device, e.g. the device creating the java.net.ServerSocket
.
Notes:
- The server device must be the Publisher device!
- The port information can only be specified on secure links, specified using
setDataPathSecurityConfig(android.net.wifi.aware.WifiAwareDataPathSecurityConfig)
Parameters | |
---|---|
port |
Int: A positive integer indicating the port to be used for communication. Value is between 0 and 65535 inclusive |
Return | |
---|---|
WifiAwareNetworkSpecifier.Builder |
the current Builder builder, enabling chaining of builder methods. This value cannot be null . |
setPskPassphrase
fun setPskPassphrase(pskPassphrase: String): WifiAwareNetworkSpecifier.Builder
Configure the PSK Passphrase for the Wi-Fi Aware connection being requested. This method is optional - if not called, then an Open (unencrypted) connection will be created. Note: Use setDataPathSecurityConfig(android.net.wifi.aware.WifiAwareDataPathSecurityConfig)
to avoid interoperability issues when devices support different cipher suites by explicitly specifying a cipher suite as opposed to relying on a default cipher suite. WifiAwareDataPathSecurityConfig.Builder#Builder(int)
Parameters | |
---|---|
pskPassphrase |
String: The (optional) passphrase to be used to encrypt the link. Use the setPmk(byte[]) to specify a PMK. This value cannot be null . |
Return | |
---|---|
WifiAwareNetworkSpecifier.Builder |
the current Builder builder, enabling chaining of builder methods. This value cannot be null . |
setTransportProtocol
fun setTransportProtocol(transportProtocol: Int): WifiAwareNetworkSpecifier.Builder
Configure the transport protocol which will be used to create a connection over this link. This configuration should only be done on the server device, e.g. the device creating the java.net.ServerSocket
for TCP.
Notes:
- The server device must be the Publisher device!
- The transport protocol information can only be specified on secure links, specified using
setDataPathSecurityConfig(android.net.wifi.aware.WifiAwareDataPathSecurityConfig)
.
Parameters | |
---|---|
transportProtocol |
Int: The transport protocol to be used for communication. Value is between 0 and 255 inclusive |
Return | |
---|---|
WifiAwareNetworkSpecifier.Builder |
the current Builder builder, enabling chaining of builder methods. This value cannot be null . |