diff --git a/wifi/java/android/net/wifi/nan/IWifiNanManager.aidl b/wifi/java/android/net/wifi/nan/IWifiNanManager.aidl index 006097df08bed..56baba9141aa6 100644 --- a/wifi/java/android/net/wifi/nan/IWifiNanManager.aidl +++ b/wifi/java/android/net/wifi/nan/IWifiNanManager.aidl @@ -50,8 +50,8 @@ interface IWifiNanManager // session API void updatePublish(int clientId, int discoverySessionId, in PublishConfig publishConfig); void updateSubscribe(int clientId, int discoverySessionId, in SubscribeConfig subscribeConfig); - void sendMessage(int clientId, int discoverySessionId, int peerId, in byte[] message, int messageId, - int retryCount); + void sendMessage(int clientId, int discoverySessionId, int peerId, in byte[] message, + int messageId, int retryCount); void terminateSession(int clientId, int discoverySessionId); int startRanging(int clientId, int discoverySessionId, in RttManager.ParcelableRttParams parms); } diff --git a/wifi/java/android/net/wifi/nan/WifiNanDiscoveryBaseSession.java b/wifi/java/android/net/wifi/nan/WifiNanDiscoveryBaseSession.java index fa2b54735cc11..b3722468afee8 100644 --- a/wifi/java/android/net/wifi/nan/WifiNanDiscoveryBaseSession.java +++ b/wifi/java/android/net/wifi/nan/WifiNanDiscoveryBaseSession.java @@ -31,8 +31,8 @@ import java.lang.ref.WeakReference; * {@link WifiNanPublishDiscoverySession} and {@link WifiNanSubscribeDiscoverySession}. This * class provides functionality common to both publish and subscribe discovery sessions: * @@ -61,7 +61,7 @@ public class WifiNanDiscoveryBaseSession { /** * Return the maximum permitted retry count when sending messages using - * {@link #sendMessage(int, int, byte[], int)}. + * {@link #sendMessage(Object, int, byte[], int)}. * * @return Maximum retry count when sending messages. */ @@ -138,7 +138,7 @@ public class WifiNanDiscoveryBaseSession { /** * Sends a message to the specified destination. NAN messages are transmitted in the context * of a discovery session - executed subsequent to a publish/subscribe - * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(int, byte[], byte[])} event. + * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} event. *

* NAN messages are not guaranteed delivery. Callbacks on * {@link WifiNanDiscoverySessionCallback} indicate message was transmitted successfully, @@ -147,12 +147,12 @@ public class WifiNanDiscoveryBaseSession { * {@link WifiNanDiscoverySessionCallback#onMessageSendFailed(int)}. *

* The peer will get a callback indicating a message was received using - * {@link WifiNanDiscoverySessionCallback#onMessageReceived(int, byte[])}. + * {@link WifiNanDiscoverySessionCallback#onMessageReceived(Object, byte[])}. * - * @param peerId The peer's ID for the message. Must be a result of an - * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(int, byte[], byte[])} - * or - * {@link WifiNanDiscoverySessionCallback#onMessageReceived(int, byte[])} events. + * @param peerHandle The peer's handle for the message. Must be a result of an + * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} + * or + * {@link WifiNanDiscoverySessionCallback#onMessageReceived(Object, byte[])} events. * @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 * failure. The {@code messageId} is not used internally by the NAN service - it @@ -163,7 +163,8 @@ public class WifiNanDiscoveryBaseSession { * (note: no retransmissions are attempted in other failure cases). A value of 0 * indicates no retries. Max permitted value is {@link #getMaxSendRetryCount()}. */ - public void sendMessage(int peerId, int messageId, @Nullable byte[] message, int retryCount) { + public void sendMessage(Object peerHandle, int messageId, @Nullable byte[] message, + int retryCount) { if (mTerminated) { Log.w(TAG, "sendMessage: called on terminated session"); return; @@ -174,14 +175,14 @@ public class WifiNanDiscoveryBaseSession { return; } - mgr.sendMessage(mClientId, mSessionId, peerId, message, messageId, retryCount); + mgr.sendMessage(mClientId, mSessionId, peerHandle, message, messageId, retryCount); } } /** * Sends a message to the specified destination. NAN messages are transmitted in the context * of a discovery session - executed subsequent to a publish/subscribe - * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(int, byte[], byte[])} event. + * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} event. *

* NAN messages are not guaranteed delivery. Callbacks on * {@link WifiNanDiscoverySessionCallback} indicate message was transmitted successfully, @@ -190,29 +191,29 @@ public class WifiNanDiscoveryBaseSession { * {@link WifiNanDiscoverySessionCallback#onMessageSendFailed(int)}. *

* The peer will get a callback indicating a message was received using - * {@link WifiNanDiscoverySessionCallback#onMessageReceived(int, byte[])}. - * Equivalent to {@link #sendMessage(int, int, byte[], int)} with a {@code retryCount} of + * {@link WifiNanDiscoverySessionCallback#onMessageReceived(Object, byte[])}. + * Equivalent to {@link #sendMessage(Object, int, byte[], int)} with a {@code retryCount} of * 0. * - * @param peerId The peer's ID for the message. Must be a result of an - * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(int, byte[], byte[])} - * or - * {@link WifiNanDiscoverySessionCallback#onMessageReceived(int, byte[])} events. + * @param peerHandle The peer's handle for the message. Must be a result of an + * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} + * or + * {@link WifiNanDiscoverySessionCallback#onMessageReceived(Object, byte[])} events. * @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 * failure. The {@code messageId} is not used internally by the NAN service - it * can be arbitrary and non-unique. * @param message The message to be transmitted. */ - public void sendMessage(int peerId, int messageId, @Nullable byte[] message) { - sendMessage(peerId, messageId, message, 0); + public void sendMessage(Object peerHandle, int messageId, @Nullable byte[] message) { + sendMessage(peerHandle, messageId, message, 0); } /** * Start a ranging operation with the specified peers. The peer IDs are obtained from an - * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(int, byte[], byte[])} or - * {@link WifiNanDiscoverySessionCallback#onMessageReceived(int, byte[])} operation - can only - * range devices which are part of an ongoing discovery session. + * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} or + * {@link WifiNanDiscoverySessionCallback#onMessageReceived(Object, byte[])} operation - can + * 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 * must be identical). The @@ -252,12 +253,12 @@ public class WifiNanDiscoveryBaseSession { * @param role The role of this device: * {@link WifiNanManager#WIFI_NAN_DATA_PATH_ROLE_INITIATOR} or * {@link WifiNanManager#WIFI_NAN_DATA_PATH_ROLE_RESPONDER} - * @param peerId The peer ID obtained through - * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(int, byte[], byte[])} or - * {@link WifiNanDiscoverySessionCallback#onMessageReceived(int, byte[])}. On a RESPONDER this - * value is used to gate the acceptance of a connection request from only that - * peer. A RESPONDER may specified a 0 - indicating that it will accept - * connection requests from any device. + * @param peerHandle The peer's handle obtained through + * {@link WifiNanDiscoverySessionCallback#onServiceDiscovered(Object, byte[], byte[])} or + * {@link WifiNanDiscoverySessionCallback#onMessageReceived(Object, byte[])}. On a RESPONDER + * this value is used to gate the acceptance of a connection request 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 * 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 @@ -269,7 +270,7 @@ public class WifiNanDiscoveryBaseSession { * {@link android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest,android.net.ConnectivityManager.NetworkCallback)} * [or other varieties of that API]. */ - public String createNetworkSpecifier(@WifiNanManager.DataPathRole int role, int peerId, + public String createNetworkSpecifier(@WifiNanManager.DataPathRole int role, Object peerHandle, @Nullable byte[] token) { if (mTerminated) { Log.w(TAG, "createNetworkSpecifier: called on terminated session"); @@ -281,7 +282,7 @@ public class WifiNanDiscoveryBaseSession { return null; } - return mgr.createNetworkSpecifier(mClientId, role, mSessionId, peerId, token); + return mgr.createNetworkSpecifier(mClientId, role, mSessionId, peerHandle, token); } } } diff --git a/wifi/java/android/net/wifi/nan/WifiNanDiscoverySessionCallback.java b/wifi/java/android/net/wifi/nan/WifiNanDiscoverySessionCallback.java index 058845fb1573e..271f420272e57 100644 --- a/wifi/java/android/net/wifi/nan/WifiNanDiscoverySessionCallback.java +++ b/wifi/java/android/net/wifi/nan/WifiNanDiscoverySessionCallback.java @@ -125,19 +125,20 @@ public class WifiNanDiscoverySessionCallback { * Called when a discovery (publish or subscribe) operation results in a * service discovery. * - * @param peerId The ID of the peer matching our discovery operation. + * @param peerHandle An opaque handle to the peer matching our discovery operation. * @param serviceSpecificInfo The service specific information (arbitrary * byte array) provided by the peer as part of its discovery * configuration. * @param matchFilter The filter (Tx on advertiser and Rx on listener) which * resulted in this service discovery. */ - public void onServiceDiscovered(int peerId, byte[] serviceSpecificInfo, byte[] matchFilter) { + public void onServiceDiscovered(Object peerHandle, byte[] serviceSpecificInfo, + byte[] matchFilter) { /* empty */ } /** - * Called in response to {@link WifiNanDiscoveryBaseSession#sendMessage(int, int, byte[])} + * Called in response to {@link WifiNanDiscoveryBaseSession#sendMessage(Object, int, byte[])} * when a message is transmitted successfully - i.e. when it was received successfully by the * peer (corresponds to an ACK being received). *

@@ -154,7 +155,7 @@ public class WifiNanDiscoverySessionCallback { /** * 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 NAN stack (using - * the {@link WifiNanDiscoveryBaseSession#sendMessage(int, int, byte[], int)} method) - this + * the {@link WifiNanDiscoveryBaseSession#sendMessage(Object, int, byte[], int)} method) - this * event is received after all retries are exhausted. *

* Note that either this callback or @@ -169,13 +170,13 @@ public class WifiNanDiscoverySessionCallback { /** * Called when a message is received from a discovery session peer - in response to the - * peer's {@link WifiNanDiscoveryBaseSession#sendMessage(int, int, byte[])} or - * {@link WifiNanDiscoveryBaseSession#sendMessage(int, int, byte[], int)}. + * peer's {@link WifiNanDiscoveryBaseSession#sendMessage(Object, int, byte[])} or + * {@link WifiNanDiscoveryBaseSession#sendMessage(Object, int, byte[], int)}. * - * @param peerId The ID of the peer sending the message. + * @param peerHandle An opaque handle to the peer matching our discovery operation. * @param message A byte array containing the message. */ - public void onMessageReceived(int peerId, byte[] message) { + public void onMessageReceived(Object peerHandle, byte[] message) { /* empty */ } } diff --git a/wifi/java/android/net/wifi/nan/WifiNanManager.java b/wifi/java/android/net/wifi/nan/WifiNanManager.java index 380924f27a13d..0d6ee94a1156a 100644 --- a/wifi/java/android/net/wifi/nan/WifiNanManager.java +++ b/wifi/java/android/net/wifi/nan/WifiNanManager.java @@ -63,7 +63,7 @@ import java.util.Arrays; *

  • Create a NAN network specifier to be used with * {@link ConnectivityManager#requestNetwork(NetworkRequest, ConnectivityManager.NetworkCallback)} * to set-up a NAN connection with a peer. Refer to - * {@link WifiNanDiscoveryBaseSession#createNetworkSpecifier(int, int, byte[])} and + * {@link WifiNanDiscoveryBaseSession#createNetworkSpecifier(int, Object, byte[])} and * {@link WifiNanSession#createNetworkSpecifier(int, byte[], byte[])}. * *

    @@ -86,8 +86,8 @@ import java.util.Arrays; *

    * Once a NAN attach is confirmed use the * {@link WifiNanSession#publish(Handler, PublishConfig, WifiNanDiscoverySessionCallback)} or - * {@link WifiNanSession#subscribe(Handler, SubscribeConfig, WifiNanDiscoverySessionCallback)} to - * create publish or subscribe NAN discovery sessions. Events are called on the provided + * {@link WifiNanSession#subscribe(Handler, SubscribeConfig, WifiNanDiscoverySessionCallback)} + * to create publish or subscribe NAN discovery sessions. Events are called on the provided * callback object {@link WifiNanDiscoverySessionCallback}. Specifically, the * {@link WifiNanDiscoverySessionCallback#onPublishStarted(WifiNanPublishDiscoverySession)} * and @@ -97,8 +97,8 @@ import java.util.Arrays; * the session {@link WifiNanPublishDiscoverySession#updatePublish(PublishConfig)} and * {@link WifiNanSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. Sessions can also * be used to send messages using the - * {@link WifiNanDiscoveryBaseSession#sendMessage(int, int, byte[])} APIs. When an application - * is finished with a discovery session it must terminate it using the + * {@link WifiNanDiscoveryBaseSession#sendMessage(Object, int, byte[])} APIs. When an + * application is finished with a discovery session it must terminate it using the * {@link WifiNanDiscoveryBaseSession#destroy()} API. *

    * Creating connections between NAN devices is managed by the standard @@ -109,7 +109,7 @@ import java.util.Arrays; * {@link android.net.NetworkCapabilities#TRANSPORT_WIFI_NAN}. *

  • {@link NetworkRequest.Builder#setNetworkSpecifier(String)} using * {@link WifiNanSession#createNetworkSpecifier(int, byte[], byte[])} or - * {@link WifiNanDiscoveryBaseSession#createNetworkSpecifier(int, int, byte[])}. + * {@link WifiNanDiscoveryBaseSession#createNetworkSpecifier(int, Object, byte[])}. * * * @hide PROPOSED_NAN_API @@ -217,7 +217,7 @@ public class WifiNanManager { * Connection creation role is that of INITIATOR. Used to create a network specifier string * when requesting a NAN network. * - * @see WifiNanDiscoveryBaseSession#createNetworkSpecifier(int, int, byte[]) + * @see WifiNanDiscoveryBaseSession#createNetworkSpecifier(int, Object, byte[]) * @see WifiNanSession#createNetworkSpecifier(int, byte[], byte[]) */ public static final int WIFI_NAN_DATA_PATH_ROLE_INITIATOR = 0; @@ -226,7 +226,7 @@ public class WifiNanManager { * Connection creation role is that of RESPONDER. Used to create a network specifier string * when requesting a NAN network. * - * @see WifiNanDiscoveryBaseSession#createNetworkSpecifier(int, int, byte[]) + * @see WifiNanDiscoveryBaseSession#createNetworkSpecifier(int, Object, byte[]) * @see WifiNanSession#createNetworkSpecifier(int, byte[], byte[]) */ public static final int WIFI_NAN_DATA_PATH_ROLE_RESPONDER = 1; @@ -457,16 +457,17 @@ public class WifiNanManager { } /** @hide */ - public void sendMessage(int clientId, int sessionId, int peerId, byte[] message, int messageId, - int retryCount) { + public void sendMessage(int clientId, int sessionId, Object peerHandle, byte[] message, + int messageId, int retryCount) { if (VDBG) { - Log.v(TAG, - "sendMessage(): clientId=" + clientId + ", sessionId=" + sessionId + ", peerId=" - + peerId + ", messageId=" + messageId + ", retryCount=" + retryCount); + Log.v(TAG, "sendMessage(): clientId=" + clientId + ", sessionId=" + sessionId + + ", peerHandle=" + peerHandle + ", messageId=" + messageId + ", retryCount=" + + retryCount); } try { - mService.sendMessage(clientId, sessionId, peerId, message, messageId, retryCount); + mService.sendMessage(clientId, sessionId, (Integer) peerHandle, message, messageId, + retryCount); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -494,19 +495,19 @@ public class WifiNanManager { } /** @hide */ - public String createNetworkSpecifier(int clientId, int role, int sessionId, int peerId, + public String createNetworkSpecifier(int clientId, int role, int sessionId, Object peerHandle, byte[] token) { if (VDBG) { Log.v(TAG, "createNetworkSpecifier: role=" + role + ", sessionId=" + sessionId - + ", peerId=" + peerId + ", token=" + token); + + ", peerHandle=" + peerHandle + ", token=" + token); } int type; - if (token != null && peerId != 0) { + if (token != null && peerHandle != null) { type = NETWORK_SPECIFIER_TYPE_1A; - } else if (token == null && peerId != 0) { + } else if (token == null && peerHandle != null) { type = NETWORK_SPECIFIER_TYPE_1B; - } else if (token != null && peerId == 0) { + } else if (token != null && peerHandle == null) { type = NETWORK_SPECIFIER_TYPE_1C; } else { type = NETWORK_SPECIFIER_TYPE_1D; @@ -523,10 +524,10 @@ public class WifiNanManager { throw new IllegalArgumentException( "createNetworkSpecifier: Invalid null token - not permitted on INITIATOR"); } - if (peerId == 0) { + if (peerHandle == null) { throw new IllegalArgumentException( - "createNetworkSpecifier: Invalid peer ID (value of 0) - not permitted on " - + "INITIATOR"); + "createNetworkSpecifier: Invalid peer handle (value of null) - not " + + "permitted on INITIATOR"); } } @@ -537,8 +538,8 @@ public class WifiNanManager { json.put(NETWORK_SPECIFIER_KEY_ROLE, role); json.put(NETWORK_SPECIFIER_KEY_CLIENT_ID, clientId); json.put(NETWORK_SPECIFIER_KEY_SESSION_ID, sessionId); - if (peerId != 0) { - json.put(NETWORK_SPECIFIER_KEY_PEER_ID, peerId); + if (peerHandle != null) { + json.put(NETWORK_SPECIFIER_KEY_PEER_ID, (Integer) peerHandle); } if (token != null) { json.put(NETWORK_SPECIFIER_KEY_TOKEN, @@ -552,8 +553,8 @@ public class WifiNanManager { } /** @hide */ - public String createNetworkSpecifier(int clientId, @DataPathRole int role, @Nullable byte[] peer, - @Nullable byte[] token) { + public String createNetworkSpecifier(int clientId, @DataPathRole int role, + @Nullable byte[] peer, @Nullable byte[] token) { if (VDBG) { Log.v(TAG, "createNetworkSpecifier: role=" + role + ", token=" + token); } @@ -843,7 +844,7 @@ public class WifiNanManager { break; case CALLBACK_MATCH: mOriginalCallback.onServiceDiscovered( - msg.arg1, + Integer.valueOf(msg.arg1), msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE), msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE2)); break; @@ -854,7 +855,8 @@ public class WifiNanManager { mOriginalCallback.onMessageSendFailed(msg.arg1); break; case CALLBACK_MESSAGE_RECEIVED: - mOriginalCallback.onMessageReceived(msg.arg1, (byte[]) msg.obj); + mOriginalCallback.onMessageReceived(Integer.valueOf(msg.arg1), + (byte[]) msg.obj); break; } } diff --git a/wifi/java/android/net/wifi/nan/WifiNanSession.java b/wifi/java/android/net/wifi/nan/WifiNanSession.java index d4249d0ba7574..5fb2c066d9b95 100644 --- a/wifi/java/android/net/wifi/nan/WifiNanSession.java +++ b/wifi/java/android/net/wifi/nan/WifiNanSession.java @@ -98,7 +98,8 @@ public class WifiNanSession { * the specified {@code publishConfig} configuration. The results of the publish operation * are routed to the callbacks of {@link WifiNanDiscoverySessionCallback}: *