Merge "[AWARE] Update API per review" am: 9e4f111e0f

am: ce7f932be7

Change-Id: I4702d65237c4a56b1f2cad2bf5e3505f1cd4ecfc
This commit is contained in:
Etan Cohen
2016-11-21 21:58:55 +00:00
committed by android-build-merger
10 changed files with 132 additions and 124 deletions

View File

@@ -32,9 +32,8 @@ import java.util.Arrays;
/** /**
* Defines the configuration of a Aware publish session. Built using * Defines the configuration of a Aware publish session. Built using
* {@link PublishConfig.Builder}. A publish session is created using * {@link PublishConfig.Builder}. A publish session is created using
* {@link WifiAwareSession#publish(android.os.Handler, PublishConfig, * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback,
* WifiAwareDiscoverySessionCallback)} * android.os.Handler)} or updated using
* or updated using
* {@link WifiAwarePublishDiscoverySession#updatePublish(PublishConfig)}. * {@link WifiAwarePublishDiscoverySession#updatePublish(PublishConfig)}.
* *
* @hide PROPOSED_AWARE_API * @hide PROPOSED_AWARE_API

View File

@@ -32,9 +32,8 @@ import java.util.Arrays;
/** /**
* Defines the configuration of a Aware subscribe session. Built using * Defines the configuration of a Aware subscribe session. Built using
* {@link SubscribeConfig.Builder}. Subscribe is done using * {@link SubscribeConfig.Builder}. Subscribe is done using
* {@link WifiAwareSession#subscribe(android.os.Handler, SubscribeConfig, * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback,
* WifiAwareDiscoverySessionCallback)} * android.os.Handler)} or
* or
* {@link WifiAwareSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. * {@link WifiAwareSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}.
* *
* @hide PROPOSED_AWARE_API * @hide PROPOSED_AWARE_API
@@ -403,8 +402,8 @@ public final class SubscribeConfig implements Parcelable {
* Sets the match style of the subscription - how are matches from a * Sets the match style of the subscription - how are matches from a
* single match session (corresponding to the same publish action on the * single match session (corresponding to the same publish action on the
* peer) reported to the host (using the * peer) reported to the host (using the
* {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle,
* ). The options are: only report the first match and ignore the rest * byte[], byte[])}). The options are: only report the first match and ignore the rest
* {@link SubscribeConfig#MATCH_STYLE_FIRST_ONLY} or report every single * {@link SubscribeConfig#MATCH_STYLE_FIRST_ONLY} or report every single
* match {@link SubscribeConfig#MATCH_STYLE_ALL} (the default). * match {@link SubscribeConfig#MATCH_STYLE_ALL} (the default).
* *

View File

@@ -18,7 +18,7 @@ package android.net.wifi.aware;
/** /**
* Base class for Aware attach callbacks. Should be extended by applications and set when calling * Base class for Aware attach callbacks. Should be extended by applications and set when calling
* {@link WifiAwareManager#attach(android.os.Handler, WifiAwareAttachCallback)}. These are callbacks * {@link WifiAwareManager#attach(WifiAwareAttachCallback, android.os.Handler)}. These are callbacks
* applying to the Aware connection as a whole - not to specific publish or subscribe sessions - * applying to the Aware connection as a whole - not to specific publish or subscribe sessions -
* for that see {@link WifiAwareDiscoverySessionCallback}. * for that see {@link WifiAwareDiscoverySessionCallback}.
* *
@@ -27,7 +27,7 @@ package android.net.wifi.aware;
public class WifiAwareAttachCallback { public class WifiAwareAttachCallback {
/** /**
* Called when Aware attach operation * Called when Aware attach operation
* {@link WifiAwareManager#attach(android.os.Handler, WifiAwareAttachCallback)} * {@link WifiAwareManager#attach(WifiAwareAttachCallback, android.os.Handler)}
* is completed and that we can now start discovery sessions or connections. * is completed and that we can now start discovery sessions or connections.
* *
* @param session The Aware object on which we can execute further Aware operations - e.g. * @param session The Aware object on which we can execute further Aware operations - e.g.
@@ -39,7 +39,7 @@ public class WifiAwareAttachCallback {
/** /**
* Called when Aware attach operation * Called when Aware attach operation
* {@link WifiAwareManager#attach(android.os.Handler, WifiAwareAttachCallback)} failed. * {@link WifiAwareManager#attach(WifiAwareAttachCallback, android.os.Handler)} failed.
*/ */
public void onAttachFailed() { public void onAttachFailed() {
/* empty */ /* empty */

View File

@@ -58,7 +58,8 @@ public class WifiAwareCharacteristics implements Parcelable {
* message exchange. Restricts the parameters of the * message exchange. Restricts the parameters of the
* {@link PublishConfig.Builder#setServiceSpecificInfo(byte[])}, * {@link PublishConfig.Builder#setServiceSpecificInfo(byte[])},
* {@link SubscribeConfig.Builder#setServiceSpecificInfo(byte[])}, and * {@link SubscribeConfig.Builder#setServiceSpecificInfo(byte[])}, and
* {@link WifiAwareDiscoveryBaseSession#sendMessage(Object, int, byte[])} variants. * {@link WifiAwareDiscoveryBaseSession#sendMessage(WifiAwareManager.PeerHandle, int, byte[])}
* variants.
* *
* @return A positive integer, maximum length of byte array for Aware messaging. * @return A positive integer, maximum length of byte array for Aware messaging.
*/ */

View File

@@ -32,10 +32,10 @@ import java.lang.ref.WeakReference;
* {@link WifiAwarePublishDiscoverySession} and {@link WifiAwareSubscribeDiscoverySession}. This * {@link WifiAwarePublishDiscoverySession} and {@link WifiAwareSubscribeDiscoverySession}. This
* class provides functionality common to both publish and subscribe discovery sessions: * class provides functionality common to both publish and subscribe discovery sessions:
* <ul> * <ul>
* <li>Sending messages: {@link #sendMessage(Object, int, byte[])} or * <li>Sending messages: {@link #sendMessage(WifiAwareManager.PeerHandle, int, byte[])} or
* {@link #sendMessage(Object, int, byte[], int)} methods. * {@link #sendMessage(WifiAwareManager.PeerHandle, int, byte[], int)} methods.
* <li>Creating a network-specifier when requesting a Aware connection: * <li>Creating a network-specifier when requesting a Aware connection:
* {@link #createNetworkSpecifier(int, Object, byte[])}. * {@link #createNetworkSpecifier(int, WifiAwareManager.PeerHandle, byte[])}.
* </ul> * </ul>
* The {@link #destroy()} method must be called to destroy discovery sessions once they are * The {@link #destroy()} method must be called to destroy discovery sessions once they are
* no longer needed. * no longer needed.
@@ -62,7 +62,7 @@ public class WifiAwareDiscoveryBaseSession {
/** /**
* Return the maximum permitted retry count when sending messages using * Return the maximum permitted retry count when sending messages using
* {@link #sendMessage(Object, int, byte[], int)}. * {@link #sendMessage(WifiAwareManager.PeerHandle, int, byte[], int)}.
* *
* @return Maximum retry count when sending messages. * @return Maximum retry count when sending messages.
*/ */
@@ -139,21 +139,24 @@ public class WifiAwareDiscoveryBaseSession {
/** /**
* Sends a message to the specified destination. Aware messages are transmitted in the context * Sends a message to the specified destination. Aware messages are transmitted in the context
* of a discovery session - executed subsequent to a publish/subscribe * of a discovery session - executed subsequent to a publish/subscribe
* {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} event. * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle,
* byte[], byte[])} event.
* <p> * <p>
* Aware messages are not guaranteed delivery. Callbacks on * Aware messages are not guaranteed delivery. Callbacks on
* {@link WifiAwareDiscoverySessionCallback} indicate message was transmitted successfully, * {@link WifiAwareDiscoverySessionCallback} indicate message was transmitted successfully,
* {@link WifiAwareDiscoverySessionCallback#onMessageSent(int)}, or transmission failed * {@link WifiAwareDiscoverySessionCallback#onMessageSendSucceeded(int)}, or transmission
* (possibly after several retries) - * failed (possibly after several retries) -
* {@link WifiAwareDiscoverySessionCallback#onMessageSendFailed(int)}. * {@link WifiAwareDiscoverySessionCallback#onMessageSendFailed(int)}.
* <p> * <p>
* The peer will get a callback indicating a message was received using * The peer will get a callback indicating a message was received using
* {@link WifiAwareDiscoverySessionCallback#onMessageReceived(Object, byte[])}. * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle,
* byte[])}.
* *
* @param peerHandle The peer's handle for the message. Must be a result of an * @param peerHandle The peer's handle for the message. Must be a result of an
* {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle,
* or * byte[], byte[])} or
* {@link WifiAwareDiscoverySessionCallback#onMessageReceived(Object, byte[])} events. * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle,
* byte[])} events.
* @param messageId An arbitrary integer used by the caller to identify the message. The same * @param messageId An arbitrary integer used by the caller to identify the message. The same
* integer ID will be returned in the callbacks indicating message send success or * integer ID will be returned in the callbacks indicating message send success or
* failure. The {@code messageId} is not used internally by the Aware service - it * failure. The {@code messageId} is not used internally by the Aware service - it
@@ -164,8 +167,8 @@ public class WifiAwareDiscoveryBaseSession {
* (note: no retransmissions are attempted in other failure cases). A value of 0 * (note: no retransmissions are attempted in other failure cases). A value of 0
* indicates no retries. Max permitted value is {@link #getMaxSendRetryCount()}. * indicates no retries. Max permitted value is {@link #getMaxSendRetryCount()}.
*/ */
public void sendMessage(@NonNull Object peerHandle, int messageId, @Nullable byte[] message, public void sendMessage(@NonNull WifiAwareManager.PeerHandle peerHandle, int messageId,
int retryCount) { @Nullable byte[] message, int retryCount) {
if (mTerminated) { if (mTerminated) {
Log.w(TAG, "sendMessage: called on terminated session"); Log.w(TAG, "sendMessage: called on terminated session");
return; return;
@@ -183,37 +186,43 @@ public class WifiAwareDiscoveryBaseSession {
/** /**
* Sends a message to the specified destination. Aware messages are transmitted in the context * Sends a message to the specified destination. Aware messages are transmitted in the context
* of a discovery session - executed subsequent to a publish/subscribe * of a discovery session - executed subsequent to a publish/subscribe
* {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} event. * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle,
* byte[], byte[])} event.
* <p> * <p>
* Aware messages are not guaranteed delivery. Callbacks on * Aware messages are not guaranteed delivery. Callbacks on
* {@link WifiAwareDiscoverySessionCallback} indicate message was transmitted successfully, * {@link WifiAwareDiscoverySessionCallback} indicate message was transmitted successfully,
* {@link WifiAwareDiscoverySessionCallback#onMessageSent(int)}, or transmission failed * {@link WifiAwareDiscoverySessionCallback#onMessageSendSucceeded(int)}, or transmission
* (possibly after several retries) - * failed (possibly after several retries) -
* {@link WifiAwareDiscoverySessionCallback#onMessageSendFailed(int)}. * {@link WifiAwareDiscoverySessionCallback#onMessageSendFailed(int)}.
* <p> * <p>
* The peer will get a callback indicating a message was received using * The peer will get a callback indicating a message was received using
* {@link WifiAwareDiscoverySessionCallback#onMessageReceived(Object, byte[])}. * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle,
* Equivalent to {@link #sendMessage(Object, int, byte[], int)} with a {@code retryCount} of * byte[])}.
* 0. * Equivalent to {@link #sendMessage(WifiAwareManager.PeerHandle, int, byte[], int)}
* with a {@code retryCount} of 0.
* *
* @param peerHandle The peer's handle for the message. Must be a result of an * @param peerHandle The peer's handle for the message. Must be a result of an
* {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle,
* or * byte[], byte[])} or
* {@link WifiAwareDiscoverySessionCallback#onMessageReceived(Object, byte[])} events. * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle,
* byte[])} events.
* @param messageId An arbitrary integer used by the caller to identify the message. The same * @param messageId An arbitrary integer used by the caller to identify the message. The same
* integer ID will be returned in the callbacks indicating message send success or * integer ID will be returned in the callbacks indicating message send success or
* failure. The {@code messageId} is not used internally by the Aware service - it * failure. The {@code messageId} is not used internally by the Aware service - it
* can be arbitrary and non-unique. * can be arbitrary and non-unique.
* @param message The message to be transmitted. * @param message The message to be transmitted.
*/ */
public void sendMessage(@NonNull Object peerHandle, int messageId, @Nullable byte[] message) { public void sendMessage(@NonNull WifiAwareManager.PeerHandle peerHandle, int messageId,
@Nullable byte[] message) {
sendMessage(peerHandle, messageId, message, 0); sendMessage(peerHandle, messageId, message, 0);
} }
/** /**
* Start a ranging operation with the specified peers. The peer IDs are obtained from an * Start a ranging operation with the specified peers. The peer IDs are obtained from an
* {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} or * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle,
* {@link WifiAwareDiscoverySessionCallback#onMessageReceived(Object, byte[])} operation - can * byte[], byte[])} or
* {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle,
* byte[])} operation - can
* only range devices which are part of an ongoing discovery session. * only range devices which are part of an ongoing discovery session.
* *
* @param params RTT parameters - each corresponding to a specific peer ID (the array sizes * @param params RTT parameters - each corresponding to a specific peer ID (the array sizes
@@ -256,11 +265,12 @@ public class WifiAwareDiscoveryBaseSession {
* {@link WifiAwareManager#WIFI_AWARE_DATA_PATH_ROLE_INITIATOR} or * {@link WifiAwareManager#WIFI_AWARE_DATA_PATH_ROLE_INITIATOR} or
* {@link WifiAwareManager#WIFI_AWARE_DATA_PATH_ROLE_RESPONDER} * {@link WifiAwareManager#WIFI_AWARE_DATA_PATH_ROLE_RESPONDER}
* @param peerHandle The peer's handle obtained through * @param peerHandle The peer's handle obtained through
* {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} or * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle,
* {@link WifiAwareDiscoverySessionCallback#onMessageReceived(Object, byte[])}. On a RESPONDER * byte[], byte[])} or
* this value is used to gate the acceptance of a connection request from only * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle,
* that peer. A RESPONDER may specified a null - indicating that it will accept * byte[])}. On a RESPONDER this value is used to gate the acceptance of a connection request
* connection requests from any device. * from only that peer. A RESPONDER may specified a null - indicating that
* it will accept connection requests from any device.
* @param token An arbitrary token (message) to be used to match connection initiation request * @param token An arbitrary token (message) to be used to match connection initiation request
* to a responder setup. A RESPONDER is set up with a {@code token} which must * to a responder setup. A RESPONDER is set up with a {@code token} which must
* be matched by the token provided by the INITIATOR. A null token is permitted * be matched by the token provided by the INITIATOR. A null token is permitted
@@ -274,7 +284,7 @@ public class WifiAwareDiscoveryBaseSession {
* [or other varieties of that API]. * [or other varieties of that API].
*/ */
public String createNetworkSpecifier(@WifiAwareManager.DataPathRole int role, public String createNetworkSpecifier(@WifiAwareManager.DataPathRole int role,
@Nullable Object peerHandle, @Nullable byte[] token) { @Nullable WifiAwareManager.PeerHandle peerHandle, @Nullable byte[] token) {
if (mTerminated) { if (mTerminated) {
Log.w(TAG, "createNetworkSpecifier: called on terminated session"); Log.w(TAG, "createNetworkSpecifier: called on terminated session");
return null; return null;

View File

@@ -26,11 +26,10 @@ import java.lang.annotation.RetentionPolicy;
* Base class for Aware session events callbacks. Should be extended by * Base class for Aware session events callbacks. Should be extended by
* applications wanting notifications. The callbacks are set when a * applications wanting notifications. The callbacks are set when a
* publish or subscribe session is created using * publish or subscribe session is created using
* {@link WifiAwareSession#publish(android.os.Handler, PublishConfig, * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback,
* WifiAwareDiscoverySessionCallback)} * android.os.Handler)} or
* or * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback,
* {@link WifiAwareSession#subscribe(android.os.Handler, SubscribeConfig, * android.os.Handler)}.
* WifiAwareDiscoverySessionCallback)} .
* <p> * <p>
* A single callback is set at session creation - it cannot be replaced. * A single callback is set at session creation - it cannot be replaced.
* *
@@ -62,9 +61,8 @@ public class WifiAwareDiscoverySessionCallback {
/** /**
* Called when a publish operation is started successfully in response to a * Called when a publish operation is started successfully in response to a
* {@link WifiAwareSession#publish(android.os.Handler, PublishConfig, * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback,
* WifiAwareDiscoverySessionCallback)} * android.os.Handler)} operation.
* operation.
* *
* @param session The {@link WifiAwarePublishDiscoverySession} used to control the * @param session The {@link WifiAwarePublishDiscoverySession} used to control the
* discovery session. * discovery session.
@@ -75,9 +73,8 @@ public class WifiAwareDiscoverySessionCallback {
/** /**
* Called when a subscribe operation is started successfully in response to a * Called when a subscribe operation is started successfully in response to a
* {@link WifiAwareSession#subscribe(android.os.Handler, SubscribeConfig, * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback,
* WifiAwareDiscoverySessionCallback)} * android.os.Handler)} operation.
* operation.
* *
* @param session The {@link WifiAwareSubscribeDiscoverySession} used to control the * @param session The {@link WifiAwareSubscribeDiscoverySession} used to control the
* discovery session. * discovery session.
@@ -98,12 +95,10 @@ public class WifiAwareDiscoverySessionCallback {
/** /**
* Called when a publish or subscribe discovery session cannot be created: * Called when a publish or subscribe discovery session cannot be created:
* {@link WifiAwareSession#publish(android.os.Handler, PublishConfig, * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback,
* WifiAwareDiscoverySessionCallback)} * android.os.Handler)} or
* or * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback,
* {@link WifiAwareSession#subscribe(android.os.Handler, SubscribeConfig, * android.os.Handler)}, or when a configuration update fails:
* WifiAwareDiscoverySessionCallback)},
* or when a configuration update fails:
* {@link WifiAwarePublishDiscoverySession#updatePublish(PublishConfig)} or * {@link WifiAwarePublishDiscoverySession#updatePublish(PublishConfig)} or
* {@link WifiAwareSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. * {@link WifiAwareSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}.
* <p> * <p>
@@ -138,13 +133,14 @@ public class WifiAwareDiscoverySessionCallback {
* @param matchFilter The filter (Tx on advertiser and Rx on listener) which * @param matchFilter The filter (Tx on advertiser and Rx on listener) which
* resulted in this service discovery. * resulted in this service discovery.
*/ */
public void onServiceDiscovered(Object peerHandle, byte[] serviceSpecificInfo, public void onServiceDiscovered(WifiAwareManager.PeerHandle peerHandle,
byte[] matchFilter) { byte[] serviceSpecificInfo, byte[] matchFilter) {
/* empty */ /* empty */
} }
/** /**
* Called in response to {@link WifiAwareDiscoveryBaseSession#sendMessage(Object, int, byte[])} * Called in response to
* {@link WifiAwareDiscoveryBaseSession#sendMessage(WifiAwareManager.PeerHandle, int, byte[])}
* when a message is transmitted successfully - i.e. when it was received successfully by the * when a message is transmitted successfully - i.e. when it was received successfully by the
* peer (corresponds to an ACK being received). * peer (corresponds to an ACK being received).
* <p> * <p>
@@ -154,18 +150,18 @@ public class WifiAwareDiscoverySessionCallback {
* *
* @param messageId The arbitrary message ID specified when sending the message. * @param messageId The arbitrary message ID specified when sending the message.
*/ */
public void onMessageSent(@SuppressWarnings("unused") int messageId) { public void onMessageSendSucceeded(@SuppressWarnings("unused") int messageId) {
/* empty */ /* empty */
} }
/** /**
* Called when message transmission fails - when no ACK is received from the peer. * Called when message transmission fails - when no ACK is received from the peer.
* Retries when ACKs are not received are done by hardware, MAC, and in the Aware stack (using * Retries when ACKs are not received are done by hardware, MAC, and in the Aware stack (using
* the {@link WifiAwareDiscoveryBaseSession#sendMessage(Object, int, byte[], int)} method) - * the {@link WifiAwareDiscoveryBaseSession#sendMessage(WifiAwareManager.PeerHandle, int,
* this event is received after all retries are exhausted. * byte[], int)} method) - this event is received after all retries are exhausted.
* <p> * <p>
* Note that either this callback or * Note that either this callback or
* {@link WifiAwareDiscoverySessionCallback#onMessageSent(int)} will be received * {@link WifiAwareDiscoverySessionCallback#onMessageSendSucceeded(int)} will be received
* - never both. * - never both.
* *
* @param messageId The arbitrary message ID specified when sending the message. * @param messageId The arbitrary message ID specified when sending the message.
@@ -176,13 +172,14 @@ public class WifiAwareDiscoverySessionCallback {
/** /**
* Called when a message is received from a discovery session peer - in response to the * Called when a message is received from a discovery session peer - in response to the
* peer's {@link WifiAwareDiscoveryBaseSession#sendMessage(Object, int, byte[])} or * peer's {@link WifiAwareDiscoveryBaseSession#sendMessage(WifiAwareManager.PeerHandle, int,
* {@link WifiAwareDiscoveryBaseSession#sendMessage(Object, int, byte[], int)}. * byte[])} or {@link WifiAwareDiscoveryBaseSession#sendMessage(WifiAwareManager.PeerHandle,
* int, byte[], int)}.
* *
* @param peerHandle An opaque handle to the peer matching our discovery operation. * @param peerHandle An opaque handle to the peer matching our discovery operation.
* @param message A byte array containing the message. * @param message A byte array containing the message.
*/ */
public void onMessageReceived(Object peerHandle, byte[] message) { public void onMessageReceived(WifiAwareManager.PeerHandle peerHandle, byte[] message) {
/* empty */ /* empty */
} }
} }

View File

@@ -56,14 +56,14 @@ import java.util.Arrays;
* The class provides access to: * The class provides access to:
* <ul> * <ul>
* <li>Initialize a Aware cluster (peer-to-peer synchronization). Refer to * <li>Initialize a Aware cluster (peer-to-peer synchronization). Refer to
* {@link #attach(Handler, WifiAwareAttachCallback)}. * {@link #attach(WifiAwareAttachCallback, Handler)}.
* <li>Create discovery sessions (publish or subscribe sessions). Refer to * <li>Create discovery sessions (publish or subscribe sessions). Refer to
* {@link WifiAwareSession#publish(Handler, PublishConfig, WifiAwareDiscoverySessionCallback)} and * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback, Handler)} and
* {@link WifiAwareSession#subscribe(Handler, SubscribeConfig, WifiAwareDiscoverySessionCallback)}. * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback, Handler)}.
* <li>Create a Aware network specifier to be used with * <li>Create a Aware network specifier to be used with
* {@link ConnectivityManager#requestNetwork(NetworkRequest, ConnectivityManager.NetworkCallback)} * {@link ConnectivityManager#requestNetwork(NetworkRequest, ConnectivityManager.NetworkCallback)}
* to set-up a Aware connection with a peer. Refer to * to set-up a Aware connection with a peer. Refer to
* {@link WifiAwareDiscoveryBaseSession#createNetworkSpecifier(int, Object, byte[])} and * {@link WifiAwareDiscoveryBaseSession#createNetworkSpecifier(int, PeerHandle, byte[])} and
* {@link WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])}. * {@link WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])}.
* </ul> * </ul>
* <p> * <p>
@@ -73,7 +73,7 @@ import java.util.Arrays;
* broadcast. Note that this broadcast is not sticky - you should register for it and then * broadcast. Note that this broadcast is not sticky - you should register for it and then
* check the above API to avoid a race condition. * check the above API to avoid a race condition.
* <p> * <p>
* An application must use {@link #attach(Handler, WifiAwareAttachCallback)} to initialize a * An application must use {@link #attach(WifiAwareAttachCallback, Handler)} to initialize a
* Aware cluster - before making any other Aware operation. Aware cluster membership is a * Aware cluster - before making any other Aware operation. Aware cluster membership is a
* device-wide operation - the API guarantees that the device is in a cluster or joins a * device-wide operation - the API guarantees that the device is in a cluster or joins a
* Aware cluster (or starts one if none can be found). Information about attach success (or * Aware cluster (or starts one if none can be found). Information about attach success (or
@@ -86,12 +86,11 @@ import java.util.Arrays;
* application detaches. * application detaches.
* <p> * <p>
* Once a Aware attach is confirmed use the * Once a Aware attach is confirmed use the
* {@link WifiAwareSession#publish(Handler, PublishConfig, WifiAwareDiscoverySessionCallback)} * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback, Handler)}
* or * or
* {@link WifiAwareSession#subscribe(Handler, SubscribeConfig, * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback,
* WifiAwareDiscoverySessionCallback)} * Handler)} to create publish or subscribe Aware discovery sessions. Events are called on the
* to create publish or subscribe Aware discovery sessions. Events are called on the provided * provided callback object {@link WifiAwareDiscoverySessionCallback}. Specifically, the
* callback object {@link WifiAwareDiscoverySessionCallback}. Specifically, the
* {@link WifiAwareDiscoverySessionCallback#onPublishStarted(WifiAwarePublishDiscoverySession)} * {@link WifiAwareDiscoverySessionCallback#onPublishStarted(WifiAwarePublishDiscoverySession)}
* and * and
* {@link WifiAwareDiscoverySessionCallback#onSubscribeStarted( * {@link WifiAwareDiscoverySessionCallback#onSubscribeStarted(
@@ -102,7 +101,7 @@ import java.util.Arrays;
* the session {@link WifiAwarePublishDiscoverySession#updatePublish(PublishConfig)} and * the session {@link WifiAwarePublishDiscoverySession#updatePublish(PublishConfig)} and
* {@link WifiAwareSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. Sessions can * {@link WifiAwareSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. Sessions can
* also be used to send messages using the * also be used to send messages using the
* {@link WifiAwareDiscoveryBaseSession#sendMessage(Object, int, byte[])} APIs. When an * {@link WifiAwareDiscoveryBaseSession#sendMessage(PeerHandle, int, byte[])} APIs. When an
* application is finished with a discovery session it <b>must</b> terminate it using the * application is finished with a discovery session it <b>must</b> terminate it using the
* {@link WifiAwareDiscoveryBaseSession#destroy()} API. * {@link WifiAwareDiscoveryBaseSession#destroy()} API.
* <p> * <p>
@@ -115,7 +114,7 @@ import java.util.Arrays;
* {@link android.net.NetworkCapabilities#TRANSPORT_WIFI_AWARE}. * {@link android.net.NetworkCapabilities#TRANSPORT_WIFI_AWARE}.
* <li>{@link NetworkRequest.Builder#setNetworkSpecifier(String)} using * <li>{@link NetworkRequest.Builder#setNetworkSpecifier(String)} using
* {@link WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])} or * {@link WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])} or
* {@link WifiAwareDiscoveryBaseSession#createNetworkSpecifier(int, Object, byte[])}. * {@link WifiAwareDiscoveryBaseSession#createNetworkSpecifier(int, PeerHandle, byte[])}.
* </ul> * </ul>
* *
* @hide PROPOSED_AWARE_API * @hide PROPOSED_AWARE_API
@@ -225,7 +224,7 @@ public class WifiAwareManager {
* Connection creation role is that of INITIATOR. Used to create a network specifier string * Connection creation role is that of INITIATOR. Used to create a network specifier string
* when requesting a Aware network. * when requesting a Aware network.
* *
* @see WifiAwareDiscoveryBaseSession#createNetworkSpecifier(int, Object, byte[]) * @see WifiAwareDiscoveryBaseSession#createNetworkSpecifier(int, PeerHandle, byte[])
* @see WifiAwareSession#createNetworkSpecifier(int, byte[], byte[]) * @see WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])
*/ */
public static final int WIFI_AWARE_DATA_PATH_ROLE_INITIATOR = 0; public static final int WIFI_AWARE_DATA_PATH_ROLE_INITIATOR = 0;
@@ -234,7 +233,7 @@ public class WifiAwareManager {
* Connection creation role is that of RESPONDER. Used to create a network specifier string * Connection creation role is that of RESPONDER. Used to create a network specifier string
* when requesting a Aware network. * when requesting a Aware network.
* *
* @see WifiAwareDiscoveryBaseSession#createNetworkSpecifier(int, Object, byte[]) * @see WifiAwareDiscoveryBaseSession#createNetworkSpecifier(int, PeerHandle, byte[])
* @see WifiAwareSession#createNetworkSpecifier(int, byte[], byte[]) * @see WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])
*/ */
public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1; public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1;
@@ -326,13 +325,13 @@ public class WifiAwareManager {
* then this function will simply indicate success immediately using the same {@code * then this function will simply indicate success immediately using the same {@code
* attachCallback}. * attachCallback}.
* *
* @param attachCallback A callback for attach events, extended from
* {@link WifiAwareAttachCallback}.
* @param handler The Handler on whose thread to execute the callbacks of the {@code * @param handler The Handler on whose thread to execute the callbacks of the {@code
* attachCallback} object. If a null is provided then the application's main thread will be * attachCallback} object. If a null is provided then the application's main thread will be
* used. * used.
* @param attachCallback A callback for attach events, extended from
* {@link WifiAwareAttachCallback}.
*/ */
public void attach(@Nullable Handler handler, @NonNull WifiAwareAttachCallback attachCallback) { public void attach(@NonNull WifiAwareAttachCallback attachCallback, @Nullable Handler handler) {
attach(handler, null, attachCallback, null); attach(handler, null, attachCallback, null);
} }
@@ -352,20 +351,21 @@ public class WifiAwareManager {
* on startup and whenever it is updated (it is randomized at regular intervals for privacy). * on startup and whenever it is updated (it is randomized at regular intervals for privacy).
* The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} * The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
* permission to execute this attach request. Otherwise, use the * permission to execute this attach request. Otherwise, use the
* {@link #attach(Handler, WifiAwareAttachCallback)} version. Note that aside from permission * {@link #attach(WifiAwareAttachCallback, Handler)} version. Note that aside from permission
* requirements this listener will wake up the host at regular intervals causing higher power * requirements this listener will wake up the host at regular intervals causing higher power
* consumption, do not use it unless the information is necessary (e.g. for OOB discovery). * consumption, do not use it unless the information is necessary (e.g. for OOB discovery).
* *
* @param handler The Handler on whose thread to execute the callbacks of the {@code
* attachCallback} and {@code identityChangedListener} objects. If a null is provided then the
* application's main thread will be used.
* @param attachCallback A callback for attach events, extended from * @param attachCallback A callback for attach events, extended from
* {@link WifiAwareAttachCallback}. * {@link WifiAwareAttachCallback}.
* @param identityChangedListener A listener for changed identity, extended from * @param identityChangedListener A listener for changed identity, extended from
* {@link WifiAwareIdentityChangedListener}. * {@link WifiAwareIdentityChangedListener}.
* @param handler The Handler on whose thread to execute the callbacks of the {@code
* attachCallback} and {@code identityChangedListener} objects. If a null is provided then the
* application's main thread will be used.
*/ */
public void attach(@Nullable Handler handler, @NonNull WifiAwareAttachCallback attachCallback, public void attach(@NonNull WifiAwareAttachCallback attachCallback,
@NonNull WifiAwareIdentityChangedListener identityChangedListener) { @NonNull WifiAwareIdentityChangedListener identityChangedListener,
@Nullable Handler handler) {
attach(handler, null, attachCallback, identityChangedListener); attach(handler, null, attachCallback, identityChangedListener);
} }
@@ -481,7 +481,7 @@ public class WifiAwareManager {
} }
/** @hide */ /** @hide */
public void sendMessage(int clientId, int sessionId, Object peerHandle, byte[] message, public void sendMessage(int clientId, int sessionId, PeerHandle peerHandle, byte[] message,
int messageId, int retryCount) { int messageId, int retryCount) {
if (peerHandle == null) { if (peerHandle == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
@@ -490,13 +490,13 @@ public class WifiAwareManager {
if (VDBG) { if (VDBG) {
Log.v(TAG, "sendMessage(): clientId=" + clientId + ", sessionId=" + sessionId Log.v(TAG, "sendMessage(): clientId=" + clientId + ", sessionId=" + sessionId
+ ", peerHandle=" + ((OpaquePeerHandle) peerHandle).peerId + ", messageId=" + ", peerHandle=" + peerHandle.peerId + ", messageId="
+ messageId + ", retryCount=" + retryCount); + messageId + ", retryCount=" + retryCount);
} }
try { try {
mService.sendMessage(clientId, sessionId, ((OpaquePeerHandle) peerHandle).peerId, mService.sendMessage(clientId, sessionId, peerHandle.peerId, message, messageId,
message, messageId, retryCount); retryCount);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
@@ -524,12 +524,12 @@ public class WifiAwareManager {
} }
/** @hide */ /** @hide */
public String createNetworkSpecifier(int clientId, int role, int sessionId, Object peerHandle, public String createNetworkSpecifier(int clientId, int role, int sessionId,
byte[] token) { PeerHandle peerHandle, byte[] token) {
if (VDBG) { if (VDBG) {
Log.v(TAG, "createNetworkSpecifier: role=" + role + ", sessionId=" + sessionId Log.v(TAG, "createNetworkSpecifier: role=" + role + ", sessionId=" + sessionId
+ ", peerHandle=" + ((peerHandle == null) ? peerHandle + ", peerHandle=" + ((peerHandle == null) ? peerHandle : peerHandle.peerId)
: ((OpaquePeerHandle) peerHandle).peerId) + ", token=" + token); + ", token=" + token);
} }
int type; int type;
@@ -569,7 +569,7 @@ public class WifiAwareManager {
json.put(NETWORK_SPECIFIER_KEY_CLIENT_ID, clientId); json.put(NETWORK_SPECIFIER_KEY_CLIENT_ID, clientId);
json.put(NETWORK_SPECIFIER_KEY_SESSION_ID, sessionId); json.put(NETWORK_SPECIFIER_KEY_SESSION_ID, sessionId);
if (peerHandle != null) { if (peerHandle != null) {
json.put(NETWORK_SPECIFIER_KEY_PEER_ID, ((OpaquePeerHandle) peerHandle).peerId); json.put(NETWORK_SPECIFIER_KEY_PEER_ID, peerHandle.peerId);
} }
if (token != null) { if (token != null) {
json.put(NETWORK_SPECIFIER_KEY_TOKEN, json.put(NETWORK_SPECIFIER_KEY_TOKEN,
@@ -876,18 +876,18 @@ public class WifiAwareManager {
break; break;
case CALLBACK_MATCH: case CALLBACK_MATCH:
mOriginalCallback.onServiceDiscovered( mOriginalCallback.onServiceDiscovered(
new OpaquePeerHandle(msg.arg1), new PeerHandle(msg.arg1),
msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE), msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE),
msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE2)); msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE2));
break; break;
case CALLBACK_MESSAGE_SEND_SUCCESS: case CALLBACK_MESSAGE_SEND_SUCCESS:
mOriginalCallback.onMessageSent(msg.arg1); mOriginalCallback.onMessageSendSucceeded(msg.arg1);
break; break;
case CALLBACK_MESSAGE_SEND_FAIL: case CALLBACK_MESSAGE_SEND_FAIL:
mOriginalCallback.onMessageSendFailed(msg.arg1); mOriginalCallback.onMessageSendFailed(msg.arg1);
break; break;
case CALLBACK_MESSAGE_RECEIVED: case CALLBACK_MESSAGE_RECEIVED:
mOriginalCallback.onMessageReceived(new OpaquePeerHandle(msg.arg1), mOriginalCallback.onMessageReceived(new PeerHandle(msg.arg1),
(byte[]) msg.obj); (byte[]) msg.obj);
break; break;
} }
@@ -1019,12 +1019,14 @@ public class WifiAwareManager {
} }
} }
/** @hide */ /** @hide PROPOSED_AWARE_API */
public static class OpaquePeerHandle { public static class PeerHandle {
public OpaquePeerHandle(int peerId) { /** @hide */
public PeerHandle(int peerId) {
this.peerId = peerId; this.peerId = peerId;
} }
/** @hide */
public int peerId; public int peerId;
} }
} }

View File

@@ -21,9 +21,8 @@ import android.util.Log;
/** /**
* A class representing a Aware publish session. Created when * A class representing a Aware publish session. Created when
* {@link WifiAwareSession#publish(android.os.Handler, PublishConfig, * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback,
* WifiAwareDiscoverySessionCallback)} * android.os.Handler)} is called and a discovery session is created and returned in
* is called and a discovery session is created and returned in
* {@link WifiAwareDiscoverySessionCallback#onPublishStarted(WifiAwarePublishDiscoverySession)}. See * {@link WifiAwareDiscoverySessionCallback#onPublishStarted(WifiAwarePublishDiscoverySession)}. See
* baseline functionality of all discovery sessions in {@link WifiAwareDiscoveryBaseSession}. This * baseline functionality of all discovery sessions in {@link WifiAwareDiscoveryBaseSession}. This
* object allows updating an existing/running publish discovery session using * object allows updating an existing/running publish discovery session using

View File

@@ -65,7 +65,7 @@ public class WifiAwareSession {
* session-wide destroy. * session-wide destroy.
* <p> * <p>
* An application may re-attach after a destroy using * An application may re-attach after a destroy using
* {@link WifiAwareManager#attach(Handler, WifiAwareAttachCallback)} . * {@link WifiAwareManager#attach(WifiAwareAttachCallback, Handler)} .
*/ */
public void destroy() { public void destroy() {
WifiAwareManager mgr = mMgr.get(); WifiAwareManager mgr = mMgr.get();
@@ -116,15 +116,15 @@ public class WifiAwareSession {
* <p>The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} * <p>The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
* permission to start a publish discovery session. * permission to start a publish discovery session.
* *
* @param handler The Handler on whose thread to execute the callbacks of the {@code
* callback} object. If a null is provided then the application's main thread will be used.
* @param publishConfig The {@link PublishConfig} specifying the * @param publishConfig The {@link PublishConfig} specifying the
* configuration of the requested publish session. * configuration of the requested publish session.
* @param callback A {@link WifiAwareDiscoverySessionCallback} derived object to be used for * @param callback A {@link WifiAwareDiscoverySessionCallback} derived object to be used for
* session event callbacks. * session event callbacks.
* @param handler The Handler on whose thread to execute the callbacks of the {@code
* callback} object. If a null is provided then the application's main thread will be used.
*/ */
public void publish(@Nullable Handler handler, @NonNull PublishConfig publishConfig, public void publish(@NonNull PublishConfig publishConfig,
@NonNull WifiAwareDiscoverySessionCallback callback) { @NonNull WifiAwareDiscoverySessionCallback callback, @Nullable Handler handler) {
WifiAwareManager mgr = mMgr.get(); WifiAwareManager mgr = mMgr.get();
if (mgr == null) { if (mgr == null) {
Log.e(TAG, "publish: called post GC on WifiAwareManager"); Log.e(TAG, "publish: called post GC on WifiAwareManager");
@@ -162,15 +162,15 @@ public class WifiAwareSession {
* <p>The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} * <p>The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
* permission to start a subscribe discovery session. * permission to start a subscribe discovery session.
* *
* @param handler The Handler on whose thread to execute the callbacks of the {@code
* callback} object. If a null is provided then the application's main thread will be used.
* @param subscribeConfig The {@link SubscribeConfig} specifying the * @param subscribeConfig The {@link SubscribeConfig} specifying the
* configuration of the requested subscribe session. * configuration of the requested subscribe session.
* @param callback A {@link WifiAwareDiscoverySessionCallback} derived object to be used for * @param callback A {@link WifiAwareDiscoverySessionCallback} derived object to be used for
* session event callbacks. * session event callbacks.
* @param handler The Handler on whose thread to execute the callbacks of the {@code
* callback} object. If a null is provided then the application's main thread will be used.
*/ */
public void subscribe(@Nullable Handler handler, @NonNull SubscribeConfig subscribeConfig, public void subscribe(@NonNull SubscribeConfig subscribeConfig,
@NonNull WifiAwareDiscoverySessionCallback callback) { @NonNull WifiAwareDiscoverySessionCallback callback, @Nullable Handler handler) {
WifiAwareManager mgr = mMgr.get(); WifiAwareManager mgr = mMgr.get();
if (mgr == null) { if (mgr == null) {
Log.e(TAG, "publish: called post GC on WifiAwareManager"); Log.e(TAG, "publish: called post GC on WifiAwareManager");
@@ -193,7 +193,8 @@ public class WifiAwareSession {
* This API is targeted for applications which can obtain the peer MAC address using OOB * This API is targeted for applications which can obtain the peer MAC address using OOB
* (out-of-band) discovery. Aware discovery does not provide the MAC address of the peer - * (out-of-band) discovery. Aware discovery does not provide the MAC address of the peer -
* when using Aware discovery use the alternative network specifier method - * when using Aware discovery use the alternative network specifier method -
* {@link WifiAwareDiscoveryBaseSession#createNetworkSpecifier(int, Object, byte[])}. * {@link WifiAwareDiscoveryBaseSession#createNetworkSpecifier(int,
* WifiAwareManager.PeerHandle, byte[])}.
* *
* @param role The role of this device: * @param role The role of this device:
* {@link WifiAwareManager#WIFI_AWARE_DATA_PATH_ROLE_INITIATOR} or * {@link WifiAwareManager#WIFI_AWARE_DATA_PATH_ROLE_INITIATOR} or

View File

@@ -21,8 +21,8 @@ import android.util.Log;
/** /**
* A class representing a Aware subscribe session. Created when * A class representing a Aware subscribe session. Created when
* {@link WifiAwareSession#subscribe(android.os.Handler, SubscribeConfig, * {@link WifiAwareSession#subscribe(SubscribeConfig,
* WifiAwareDiscoverySessionCallback)} * WifiAwareDiscoverySessionCallback, android.os.Handler)}
* is called and a discovery session is created and returned in * is called and a discovery session is created and returned in
* {@link WifiAwareDiscoverySessionCallback#onSubscribeStarted(WifiAwareSubscribeDiscoverySession)}. * {@link WifiAwareDiscoverySessionCallback#onSubscribeStarted(WifiAwareSubscribeDiscoverySession)}.
* See baseline functionality of all discovery sessions in {@link WifiAwareDiscoveryBaseSession}. * See baseline functionality of all discovery sessions in {@link WifiAwareDiscoveryBaseSession}.