Added in API level 26

DiscoverySessionCallback


open class DiscoverySessionCallback
kotlin.Any
   ↳ android.net.wifi.aware.DiscoverySessionCallback

Base class for Aware session events callbacks. Should be extended by applications wanting notifications. The callbacks are set when a publish or subscribe session is created using WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, or WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback,.

A single callback is set at session creation - it cannot be replaced.

Summary

Public constructors

Public methods
open Unit

Callback indicating that a Bootstrapping method negotiation failed.

open Unit
onBootstrappingSucceeded(peerHandle: PeerHandle, method: Int)

Callback indicating that a Bootstrapping method negotiation succeeded.

open Unit
onMessageReceived(peerHandle: PeerHandle!, message: ByteArray!)

Called when a message is received from a discovery session peer - in response to the peer's DiscoverySession#sendMessage(PeerHandle, int, byte[]).

open Unit

Called when message transmission initiated with DiscoverySession#sendMessage(PeerHandle, int, byte[]) fails.

open Unit

Called in response to DiscoverySession#sendMessage(PeerHandle, int, byte[]) when a message is transmitted successfully - i.

open Unit

Callback indicating that a pairing setup process failed.

open Unit
onPairingSetupRequestReceived(peerHandle: PeerHandle, requestId: Int)

Callback indicating that a pairing request is received from peer.

open Unit

Callback indicating that a pairing setup process succeeded.

open Unit

Callback indicating that a pairing verification process failed.

open Unit

Callback indicating that a pairing verification process succeeded.

open Unit

Called when a publish operation is started successfully in response to a WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, operation.

open Unit
onServiceDiscovered(peerHandle: PeerHandle!, serviceSpecificInfo: ByteArray!, matchFilter: MutableList<ByteArray!>!)

Called when a subscribe operation results in a service discovery.

open Unit

Called when a subscribe operation results in a service discovery.

open Unit
onServiceDiscoveredWithinRange(peerHandle: PeerHandle!, serviceSpecificInfo: ByteArray!, matchFilter: MutableList<ByteArray!>!, distanceMm: Int)

Called when a subscribe operation results in a service discovery.

open Unit

Called when a subscribe operation results in a service discovery.

open Unit
onServiceLost(peerHandle: PeerHandle, reason: Int)

Called when the discovered service is not available.

open Unit

Called when a publish or subscribe discovery session cannot be created: WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, or WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback,, or when a configuration update fails: PublishDiscoverySession#updatePublish(PublishConfig) or SubscribeDiscoverySession#updateSubscribe(SubscribeConfig).

open Unit

Called when a publish or subscribe discovery session configuration update request succeeds.

open Unit

Called when a discovery session (publish or subscribe) terminates.

open Unit

Called when a subscribe operation is started successfully in response to a WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, operation.

Public constructors

DiscoverySessionCallback

Added in API level 26
DiscoverySessionCallback()

Public methods

onBootstrappingFailed

Added in API level 34
open fun onBootstrappingFailed(peerHandle: PeerHandle): Unit

Callback indicating that a Bootstrapping method negotiation failed.

Parameters
peerHandle PeerHandle: The bootstrapping peer handle This value cannot be null.

onMessageReceived

Added in API level 26
open fun onMessageReceived(
    peerHandle: PeerHandle!,
    message: ByteArray!
): Unit

Called when a message is received from a discovery session peer - in response to the peer's DiscoverySession#sendMessage(PeerHandle, int, byte[]).

Parameters
peerHandle PeerHandle!: An opaque handle to the peer matching our discovery operation.
message ByteArray!: A byte array containing the message.

onMessageSendFailed

Added in API level 26
open fun onMessageSendFailed(messageId: Int): Unit

Called when message transmission initiated with DiscoverySession#sendMessage(PeerHandle, int, byte[]) fails. E.g. when no ACK is received from the peer.

Note that either this callback or DiscoverySessionCallback#onMessageSendSucceeded(int) will be received - never both.

Parameters
messageId Int: The arbitrary message ID specified when sending the message.

onMessageSendSucceeded

Added in API level 26
open fun onMessageSendSucceeded(messageId: Int): Unit

Called in response to DiscoverySession#sendMessage(PeerHandle, int, byte[]) when a message is transmitted successfully - i.e. when it was received successfully by the peer (corresponds to an ACK being received).

Note that either this callback or DiscoverySessionCallback#onMessageSendFailed(int) will be received - never both.

Parameters
messageId Int: The arbitrary message ID specified when sending the message.

onPairingSetupFailed

Added in API level 34
open fun onPairingSetupFailed(peerHandle: PeerHandle): Unit

Callback indicating that a pairing setup process failed.

Parameters
peerHandle PeerHandle: The pairing peer handle. This value cannot be null.

onPairingSetupRequestReceived

Added in API level 34
open fun onPairingSetupRequestReceived(
    peerHandle: PeerHandle,
    requestId: Int
): Unit

Callback indicating that a pairing request is received from peer.

Parameters
peerHandle PeerHandle: The peer's handle where the request is from This value cannot be null.
requestId Int: The ID of the Aware pairing session

onPairingSetupSucceeded

Added in API level 34
open fun onPairingSetupSucceeded(
    peerHandle: PeerHandle,
    alias: String
): Unit

Callback indicating that a pairing setup process succeeded.

Parameters
peerHandle PeerHandle: The pairing peer handle. This value cannot be null.
alias String: This is the paired device alias set by the caller. DiscoverySession#initiatePairingRequest(PeerHandle, String, int, String) or DiscoverySession#acceptPairingRequest(int, PeerHandle, String, int, String) This value cannot be null.

onPairingVerificationFailed

Added in API level 34
open fun onPairingVerificationFailed(peerHandle: PeerHandle): Unit

Callback indicating that a pairing verification process failed.

Parameters
peerHandle PeerHandle: The pairing peer handle This value cannot be null.

onPairingVerificationSucceed

Added in API level 34
open fun onPairingVerificationSucceed(
    peerHandle: PeerHandle,
    alias: String
): Unit

Callback indicating that a pairing verification process succeeded.

Parameters
peerHandle PeerHandle: The pairing peer handle This value cannot be null.
alias String: This is the paired device alias set by the caller. DiscoverySession#initiatePairingRequest(PeerHandle, String, int, String) or DiscoverySession#acceptPairingRequest(int, PeerHandle, String, int, String) This value cannot be null.

onPublishStarted

Added in API level 26
open fun onPublishStarted(session: PublishDiscoverySession): Unit

Called when a publish operation is started successfully in response to a WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, operation.

Parameters
session PublishDiscoverySession: The PublishDiscoverySession used to control the discovery session. This value cannot be null.

onServiceDiscovered

Added in API level 26
open fun onServiceDiscovered(
    peerHandle: PeerHandle!,
    serviceSpecificInfo: ByteArray!,
    matchFilter: MutableList<ByteArray!>!
): Unit

Called when a subscribe operation results in a service discovery.

Note that this method and onServiceDiscoveredWithinRange(android.net.wifi.aware.PeerHandle,byte[],java.util.List,int) may be called multiple times per service discovery.

Note: This method is superseded by onServiceDiscovered(android.net.wifi.aware.ServiceDiscoveryInfo) which returns more information. Note that both legacy and new callback will be triggered on discovery.

Parameters
peerHandle PeerHandle!: An opaque handle to the peer matching our discovery operation.
serviceSpecificInfo ByteArray!: The service specific information (arbitrary byte array) provided by the peer as part of its discovery configuration.
matchFilter MutableList<ByteArray!>!: The filter which resulted in this service discovery. For PublishConfig#PUBLISH_TYPE_UNSOLICITED, SubscribeConfig#SUBSCRIBE_TYPE_PASSIVE discovery sessions this is the publisher's match filter. For PublishConfig#PUBLISH_TYPE_SOLICITED, SubscribeConfig#SUBSCRIBE_TYPE_ACTIVE discovery sessions this is the subscriber's match filter.

onServiceDiscovered

Added in API level 33
open fun onServiceDiscovered(info: ServiceDiscoveryInfo): Unit

Called when a subscribe operation results in a service discovery.

Note: This method supersedes onServiceDiscovered(android.net.wifi.aware.PeerHandle,byte[],java.util.List) and provides additional information - including cipher suite type and security context of the peer. Both the legacy and the new callback will be triggered on discovery.

Parameters
info ServiceDiscoveryInfo: A ServiceDiscoveryInfo structure containing information on the discovery session and the discovered peer. This value cannot be null.

onServiceDiscoveredWithinRange

Added in API level 28
open fun onServiceDiscoveredWithinRange(
    peerHandle: PeerHandle!,
    serviceSpecificInfo: ByteArray!,
    matchFilter: MutableList<ByteArray!>!,
    distanceMm: Int
): Unit

Called when a subscribe operation results in a service discovery. Called when a Subscribe service was configured with a range requirement SubscribeConfig.Builder#setMinDistanceMm(int) and/or SubscribeConfig.Builder#setMaxDistanceMm(int) and the Publish service was configured with PublishConfig.Builder#setRangingEnabled(boolean).

If either Publisher or Subscriber does not enable Ranging, or if Ranging is temporarily disabled by the underlying device, service discovery proceeds without ranging and the onServiceDiscovered(android.net.wifi.aware.PeerHandle,byte[],java.util.List) is called.

Note that this method and onServiceDiscovered(android.net.wifi.aware.PeerHandle,byte[],java.util.List) may be called multiple times per service discovery.

Note: This method is superseded by onServiceDiscoveredWithinRange(android.net.wifi.aware.ServiceDiscoveryInfo,int) which returns more information. Note that both legacy and new callback will be triggered on discovery.

Parameters
peerHandle PeerHandle!: An opaque handle to the peer matching our discovery operation.
serviceSpecificInfo ByteArray!: The service specific information (arbitrary byte array) provided by the peer as part of its discovery configuration.
matchFilter MutableList<ByteArray!>!: The filter which resulted in this service discovery. For PublishConfig#PUBLISH_TYPE_UNSOLICITED, SubscribeConfig#SUBSCRIBE_TYPE_PASSIVE discovery sessions this is the publisher's match filter. For PublishConfig#PUBLISH_TYPE_SOLICITED, SubscribeConfig#SUBSCRIBE_TYPE_ACTIVE discovery sessions this is the subscriber's match filter.
distanceMm Int: The measured distance to the Publisher in mm. Note: the measured distance may be negative for very close devices.

onServiceDiscoveredWithinRange

Added in API level 33
open fun onServiceDiscoveredWithinRange(
    info: ServiceDiscoveryInfo,
    distanceMm: Int
): Unit

Called when a subscribe operation results in a service discovery. Called when a Subscribe service was configured with a range requirement SubscribeConfig.Builder#setMinDistanceMm(int) and/or SubscribeConfig.Builder#setMaxDistanceMm(int) and the Publish service was configured with PublishConfig.Builder#setRangingEnabled(boolean).

If either Publisher or Subscriber does not enable Ranging, or if Ranging is temporarily disabled by the underlying device, service discovery proceeds without ranging and the onServiceDiscovered(android.net.wifi.aware.PeerHandle,byte[],java.util.List) is called.

Note: This method supersedes onServiceDiscoveredWithinRange(android.net.wifi.aware.PeerHandle,byte[],java.util.List,int) and provides additional information - including cipher suite type and security context of the peer. Both the legacy and the new callback will be triggered on discovery.

Parameters
info ServiceDiscoveryInfo: A ServiceDiscoveryInfo which indicate service config of the descovery sessions. This value cannot be null.
distanceMm Int: The measured distance to the Publisher in mm. Note: the measured distance may be negative for very close devices.

onServiceLost

Added in API level 31
open fun onServiceLost(
    peerHandle: PeerHandle,
    reason: Int
): Unit

Called when the discovered service is not available. All further operations on this discovery session will fail. If the service is available again, onServiceDiscovered(android.net.wifi.aware.PeerHandle,byte[],java.util.List) or onServiceDiscoveredWithinRange(android.net.wifi.aware.PeerHandle,byte[],java.util.List,int) will be called.

Parameters
peerHandle PeerHandle: An opaque handle to the peer matching our discovery operation. This value cannot be null.
reason Int: Discovered service lost reason code. One of WifiAwareManager#WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE, android.net.wifi.aware.WifiAwareManager#WIFI_AWARE_DISCOVERY_LOST_REASON_UNKNOWN}

onSessionConfigFailed

Added in API level 26
open fun onSessionConfigFailed(): Unit

Called when a publish or subscribe discovery session cannot be created: WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, or WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback,, or when a configuration update fails: PublishDiscoverySession#updatePublish(PublishConfig) or SubscribeDiscoverySession#updateSubscribe(SubscribeConfig).

For discovery session updates failure leaves the session running with its previous configuration - the discovery session is not terminated.

onSessionConfigUpdated

Added in API level 26
open fun onSessionConfigUpdated(): Unit

Called when a publish or subscribe discovery session configuration update request succeeds. Called in response to PublishDiscoverySession#updatePublish(PublishConfig) or SubscribeDiscoverySession#updateSubscribe(SubscribeConfig).

onSessionTerminated

Added in API level 26
open fun onSessionTerminated(): Unit

Called when a discovery session (publish or subscribe) terminates. Termination may be due to user-request (either directly through DiscoverySession#close() or application-specified expiration, e.g. PublishConfig.Builder#setTtlSec(int) or SubscribeConfig.Builder#setTtlSec(int)).

onSubscribeStarted

Added in API level 26
open fun onSubscribeStarted(session: SubscribeDiscoverySession): Unit

Called when a subscribe operation is started successfully in response to a WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, operation.

Parameters
session SubscribeDiscoverySession: The SubscribeDiscoverySession used to control the discovery session. This value cannot be null.