lightbulb_outline Please take our October 2018 developer survey. Start survey

SubscribeConfig.Builder

public static final class SubscribeConfig.Builder
extends Object

java.lang.Object
   ↳ android.net.wifi.aware.SubscribeConfig.Builder


Builder used to build SubscribeConfig objects.

Summary

Public constructors

SubscribeConfig.Builder()

Public methods

SubscribeConfig build()

Build SubscribeConfig given the current requests made on the builder.

SubscribeConfig.Builder setMatchFilter(List<byte[]> matchFilter)

The match filter for a subscribe session.

SubscribeConfig.Builder setMaxDistanceMm(int maxDistanceMm)

Configure the maximum distance to a discovered publisher at which to trigger a discovery notification.

SubscribeConfig.Builder setMinDistanceMm(int minDistanceMm)

Configure the minimum distance to a discovered publisher at which to trigger a discovery notification.

SubscribeConfig.Builder setServiceName(String serviceName)

Specify the service name of the subscribe session.

SubscribeConfig.Builder setServiceSpecificInfo(byte[] serviceSpecificInfo)

Specify service specific information for the subscribe session.

SubscribeConfig.Builder setSubscribeType(int subscribeType)

Sets the type of the subscribe session: active (subscribe packets are transmitted over-the-air), or passive (no subscribe packets are transmitted, a match is made against a solicited/active publish session whose packets are transmitted over-the-air).

SubscribeConfig.Builder setTerminateNotificationEnabled(boolean enable)

Configure whether a subscribe terminate notification DiscoverySessionCallback.onSessionTerminated() is reported back to the callback.

SubscribeConfig.Builder setTtlSec(int ttlSec)

Sets the time interval (in seconds) an active ( setSubscribeType(int)) subscribe session will be alive - i.e.

Inherited methods

Public constructors

SubscribeConfig.Builder

added in API level 26
public SubscribeConfig.Builder ()

Public methods

build

added in API level 26
public SubscribeConfig build ()

Build SubscribeConfig given the current requests made on the builder.

Returns
SubscribeConfig

setMatchFilter

added in API level 26
public SubscribeConfig.Builder setMatchFilter (List<byte[]> matchFilter)

The match filter for a subscribe session. Used to determine whether a service discovery occurred - in addition to relying on the service name.

Optional. Empty by default.

Parameters
matchFilter List: A list of match filter entries (each of which is an arbitrary byte array).

This value may be null.

Returns
SubscribeConfig.Builder The builder to facilitate chaining builder.setXXX(..).setXXX(..).

setMaxDistanceMm

added in API level 28
public SubscribeConfig.Builder setMaxDistanceMm (int maxDistanceMm)

Configure the maximum distance to a discovered publisher at which to trigger a discovery notification. I.e. discovery will be triggered if we've found a matching publisher (based on the other criteria in this configuration) and the distance to the publisher is smaller than the value specified in this API. Can be used in conjunction with setMinDistanceMm(int) to specify a geofence, i.e. discovery with min <= distance <= max.

For ranging to be used in discovery it must also be enabled on the publisher using PublishConfig.Builder.setRangingEnabled(boolean). However, ranging may not be available or enabled on the publisher or may be temporarily disabled on either subscriber or publisher - in such cases discovery will proceed without ranging.

When ranging is enabled and available on both publisher and subscriber and a service is discovered based on geofence constraints the DiscoverySessionCallback.onServiceDiscoveredWithinRange(PeerHandle, byte[], List, int) is called, otherwise the DiscoverySessionCallback.onServiceDiscovered(PeerHandle, byte[], List) is called.

The device must support Wi-Fi RTT for this feature to be used. Feature support is checked as described in android.net.wifi.rtt.

Parameters
maxDistanceMm int: Maximum distance, in mm, to the publisher below which to trigger discovery.

Returns
SubscribeConfig.Builder The builder to facilitate chaining builder.setXXX(..).setXXX(..).

setMinDistanceMm

added in API level 28
public SubscribeConfig.Builder setMinDistanceMm (int minDistanceMm)

Configure the minimum distance to a discovered publisher at which to trigger a discovery notification. I.e. discovery will be triggered if we've found a matching publisher (based on the other criteria in this configuration) and the distance to the publisher is larger than the value specified in this API. Can be used in conjunction with setMaxDistanceMm(int) to specify a geofence, i.e. discovery with min <= distance <= max.

For ranging to be used in discovery it must also be enabled on the publisher using PublishConfig.Builder.setRangingEnabled(boolean). However, ranging may not be available or enabled on the publisher or may be temporarily disabled on either subscriber or publisher - in such cases discovery will proceed without ranging.

When ranging is enabled and available on both publisher and subscriber and a service is discovered based on geofence constraints the DiscoverySessionCallback.onServiceDiscoveredWithinRange(PeerHandle, byte[], List, int) is called, otherwise the DiscoverySessionCallback.onServiceDiscovered(PeerHandle, byte[], List) is called.

The device must support Wi-Fi RTT for this feature to be used. Feature support is checked as described in android.net.wifi.rtt.

Parameters
minDistanceMm int: Minimum distance, in mm, to the publisher above which to trigger discovery.

Returns
SubscribeConfig.Builder The builder to facilitate chaining builder.setXXX(..).setXXX(..).

setServiceName

added in API level 26
public SubscribeConfig.Builder setServiceName (String serviceName)

Specify the service name of the subscribe session. The actual on-air value is a 6 byte hashed representation of this string.

The Service Name is a UTF-8 encoded string from 1 to 255 bytes in length. The only acceptable single-byte UTF-8 symbols for a Service Name are alphanumeric values (A-Z, a-z, 0-9), the hyphen ('-'), and the period ('.'). All valid multi-byte UTF-8 characters are acceptable in a Service Name.

Must be called - an empty ServiceName is not valid.

Parameters
serviceName String: The service name for the subscribe session.

This value must never be null.

Returns
SubscribeConfig.Builder The builder to facilitate chaining builder.setXXX(..).setXXX(..).

setServiceSpecificInfo

added in API level 26
public SubscribeConfig.Builder setServiceSpecificInfo (byte[] serviceSpecificInfo)

Specify service specific information for the subscribe session. This is a free-form byte array available to the application to send additional information as part of the discovery operation - i.e. it will not be used to determine whether a publish/subscribe match occurs.

Optional. Empty by default.

Parameters
serviceSpecificInfo byte: A byte-array for the service-specific information field.

This value may be null.

Returns
SubscribeConfig.Builder The builder to facilitate chaining builder.setXXX(..).setXXX(..).

setSubscribeType

added in API level 26
public SubscribeConfig.Builder setSubscribeType (int subscribeType)

Sets the type of the subscribe session: active (subscribe packets are transmitted over-the-air), or passive (no subscribe packets are transmitted, a match is made against a solicited/active publish session whose packets are transmitted over-the-air).

Parameters
subscribeType int: Subscribe session type: SubscribeConfig.SUBSCRIBE_TYPE_ACTIVE or SubscribeConfig.SUBSCRIBE_TYPE_PASSIVE.

Returns
SubscribeConfig.Builder The builder to facilitate chaining builder.setXXX(..).setXXX(..).

setTerminateNotificationEnabled

added in API level 26
public SubscribeConfig.Builder setTerminateNotificationEnabled (boolean enable)

Configure whether a subscribe terminate notification DiscoverySessionCallback.onSessionTerminated() is reported back to the callback.

Parameters
enable boolean: If true the terminate callback will be called when the subscribe is terminated. Otherwise it will not be called.

Returns
SubscribeConfig.Builder The builder to facilitate chaining builder.setXXX(..).setXXX(..).

setTtlSec

added in API level 26
public SubscribeConfig.Builder setTtlSec (int ttlSec)

Sets the time interval (in seconds) an active ( setSubscribeType(int)) subscribe session will be alive - i.e. broadcasting a packet. When the TTL is reached an event will be generated for DiscoverySessionCallback.onSessionTerminated().

Optional. 0 by default - indicating the session doesn't terminate on its own. Session will be terminated when DiscoverySession.close() is called.

Parameters
ttlSec int: Lifetime of a subscribe session in seconds.

Returns
SubscribeConfig.Builder The builder to facilitate chaining builder.setXXX(..).setXXX(..).