DiscoverySessionCallback


public class DiscoverySessionCallback
extends Object

java.lang.Object
   ↳ 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, android.os.Handler) or WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, android.os.Handler).

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

Summary

Public constructors

DiscoverySessionCallback()

Public methods

void onBootstrappingFailed(PeerHandle peerHandle)

Callback indicating that a Bootstrapping method negotiation failed.

void onBootstrappingSucceeded(PeerHandle peerHandle, int method)

Callback indicating that a Bootstrapping method negotiation succeeded.

void onMessageReceived(PeerHandle peerHandle, byte[] message)

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

void onMessageSendFailed(int messageId)

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

void onMessageSendSucceeded(int messageId)

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

void onPairingSetupFailed(PeerHandle peerHandle)

Callback indicating that a pairing setup process failed.

void onPairingSetupRequestReceived(PeerHandle peerHandle, int requestId)

Callback indicating that a pairing request is received from peer.

void onPairingSetupSucceeded(PeerHandle peerHandle, String alias)

Callback indicating that a pairing setup process succeeded.

void onPairingVerificationFailed(PeerHandle peerHandle)

Callback indicating that a pairing verification process failed.

void onPairingVerificationSucceed(PeerHandle peerHandle, String alias)

Callback indicating that a pairing verification process succeeded.

void onPublishStarted(PublishDiscoverySession session)

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

void onServiceDiscovered(PeerHandle peerHandle, byte[] serviceSpecificInfo, List<byte[]> matchFilter)

Called when a subscribe operation results in a service discovery.

void onServiceDiscovered(ServiceDiscoveryInfo info)

Called when a subscribe operation results in a service discovery.

void onServiceDiscoveredWithinRange(PeerHandle peerHandle, byte[] serviceSpecificInfo, List<byte[]> matchFilter, int distanceMm)

Called when a subscribe operation results in a service discovery.

void onServiceDiscoveredWithinRange(ServiceDiscoveryInfo info, int distanceMm)

Called when a subscribe operation results in a service discovery.

void onServiceLost(PeerHandle peerHandle, int reason)

Called when the discovered service is not available.

void onSessionConfigFailed()

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

void onSessionConfigUpdated()

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

void onSessionTerminated()

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

void onSubscribeStarted(SubscribeDiscoverySession session)

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

Inherited methods

Public constructors

DiscoverySessionCallback

Added in API level 26
public DiscoverySessionCallback ()

Public methods

onBootstrappingFailed

Added in API level 34
public void onBootstrappingFailed (PeerHandle peerHandle)

Callback indicating that a Bootstrapping method negotiation failed.

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

onBootstrappingSucceeded

Added in API level 34
public void onBootstrappingSucceeded (PeerHandle peerHandle, 
                int method)

Callback indicating that a Bootstrapping method negotiation succeeded. The follow-up out-of-band bootstrapping can start

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

method int: The bootstrapping method accept by the peer Value is either 0 or a combination of AwarePairingConfig.PAIRING_BOOTSTRAPPING_OPPORTUNISTIC, AwarePairingConfig.PAIRING_BOOTSTRAPPING_PIN_CODE_DISPLAY, AwarePairingConfig.PAIRING_BOOTSTRAPPING_PASSPHRASE_DISPLAY, AwarePairingConfig.PAIRING_BOOTSTRAPPING_QR_DISPLAY, AwarePairingConfig.PAIRING_BOOTSTRAPPING_NFC_TAG, AwarePairingConfig.PAIRING_BOOTSTRAPPING_PIN_CODE_KEYPAD, AwarePairingConfig.PAIRING_BOOTSTRAPPING_PASSPHRASE_KEYPAD, AwarePairingConfig.PAIRING_BOOTSTRAPPING_QR_SCAN, and AwarePairingConfig.PAIRING_BOOTSTRAPPING_NFC_READER

onMessageReceived

Added in API level 26
public void onMessageReceived (PeerHandle peerHandle, 
                byte[] message)

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 byte: A byte array containing the message.

onMessageSendFailed

Added in API level 26
public void onMessageSendFailed (int messageId)

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
public void onMessageSendSucceeded (int messageId)

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
public void onPairingSetupFailed (PeerHandle peerHandle)

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
public void onPairingSetupRequestReceived (PeerHandle peerHandle, 
                int requestId)

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
public void onPairingSetupSucceeded (PeerHandle peerHandle, 
                String alias)

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
public void onPairingVerificationFailed (PeerHandle peerHandle)

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
public void onPairingVerificationSucceed (PeerHandle peerHandle, 
                String alias)

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
public void onPublishStarted (PublishDiscoverySession session)

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

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

onServiceDiscovered

Added in API level 26
public void onServiceDiscovered (PeerHandle peerHandle, 
                byte[] serviceSpecificInfo, 
                List<byte[]> matchFilter)

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 byte: The service specific information (arbitrary byte array) provided by the peer as part of its discovery configuration.

matchFilter List: 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
public void onServiceDiscovered (ServiceDiscoveryInfo info)

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
public void onServiceDiscoveredWithinRange (PeerHandle peerHandle, 
                byte[] serviceSpecificInfo, 
                List<byte[]> matchFilter, 
                int distanceMm)

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 byte: The service specific information (arbitrary byte array) provided by the peer as part of its discovery configuration.

matchFilter List: 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
public void onServiceDiscoveredWithinRange (ServiceDiscoveryInfo info, 
                int distanceMm)

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
public void onServiceLost (PeerHandle peerHandle, 
                int reason)

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, WifiAwareManager.WIFI_AWARE_DISCOVERY_LOST_REASON_UNKNOWN}

onSessionConfigFailed

Added in API level 26
public void onSessionConfigFailed ()

Called when a publish or subscribe discovery session cannot be created: WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, android.os.Handler) or WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, android.os.Handler), 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
public void onSessionConfigUpdated ()

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
public void onSessionTerminated ()

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
public void onSubscribeStarted (SubscribeDiscoverySession session)

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

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