Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f02ae5e2 authored by Etan Cohen's avatar Etan Cohen
Browse files

[NAN] Replace int peerId with more opaqure Object peerHandle per API review [DO NOT MERGE]

Bug: 31470256
Test: unit tests & integration (sl4a) tests.
Change-Id: I6e1973eea3c6750191b0b07ebafad73b7e95acfe
parent 905077a5
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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);
}
+32 −31
Original line number Diff line number Diff line
@@ -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:
 * <ul>
 *     <li>Sending messages: {@link #sendMessage(int, int, byte[])} or
 *     {@link #sendMessage(int, int, byte[], int)} methods.
 *     <li>Sending messages: {@link #sendMessage(Object, int, byte[])} or
 *     {@link #sendMessage(Object, int, byte[], int)} methods.
 *     <li>Creating a network-specifier when requesting a NAN connection:
 *     {@link #createNetworkSpecifier(int, int, byte[])}.
 * </ul>
@@ -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.
     * <p>
     *     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)}.
     * <p>
     *     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[])}
     * @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(int, byte[])} events.
     *        {@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.
     * <p>
     *     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)}.
     * <p>
     *     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[])}
     * @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(int, byte[])} events.
     *        {@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,11 +253,11 @@ 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
     * @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
@@ -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);
        }
    }
}
+9 −8
Original line number Diff line number Diff line
@@ -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).
     * <p>
@@ -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.
     * <p>
     * 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 */
    }
}
+30 −28
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ import java.util.Arrays;
 * <li>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[])}.
 * </ul>
 * <p>
@@ -86,8 +86,8 @@ import java.util.Arrays;
 * <p>
 *     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 <b>must</b> terminate it using the
 *     {@link WifiNanDiscoveryBaseSession#sendMessage(Object, int, byte[])} APIs. When an
 *     application is finished with a discovery session it <b>must</b> terminate it using the
 *     {@link WifiNanDiscoveryBaseSession#destroy()} API.
 * <p>
 *    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}.
 *        <li>{@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[])}.
 *    </ul>
 *
 * @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;
@@ -459,16 +459,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) {
            e.rethrowAsRuntimeException();
        }
@@ -496,19 +497,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;
@@ -525,10 +526,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");
            }
        }

@@ -539,8 +540,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,
@@ -554,8 +555,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);
        }
@@ -845,7 +846,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;
@@ -856,7 +857,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;
                    }
                }
+5 −3
Original line number Diff line number Diff line
@@ -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}:
     * <ul>
     *     <li>{@link WifiNanDiscoverySessionCallback#onPublishStarted(WifiNanPublishDiscoverySession)}
     *     <li>
     *     {@link WifiNanDiscoverySessionCallback#onPublishStarted(WifiNanPublishDiscoverySession)}
     *     is called when the publish session is created and provides a handle to the session.
     *     Further operations on the publish session can be executed on that object.
     *     <li>{@link WifiNanDiscoverySessionCallback#onSessionConfigFailed()} is called if the
@@ -140,7 +141,8 @@ public class WifiNanSession {
     * the specified {@code subscribeConfig} configuration. The results of the subscribe
     * operation are routed to the callbacks of {@link WifiNanDiscoverySessionCallback}:
     * <ul>
     *     <li>{@link WifiNanDiscoverySessionCallback#onSubscribeStarted(WifiNanSubscribeDiscoverySession)}
     *     <li>
     *  {@link WifiNanDiscoverySessionCallback#onSubscribeStarted(WifiNanSubscribeDiscoverySession)}
     *     is called when the subscribe session is created and provides a handle to the session.
     *     Further operations on the subscribe session can be executed on that object.
     *     <li>{@link WifiNanDiscoverySessionCallback#onSessionConfigFailed()} is called if the
@@ -186,7 +188,7 @@ public class WifiNanSession {
     *     This API is targeted for applications which can obtain the peer MAC address using OOB
     *     (out-of-band) discovery. NAN discovery does not provide the MAC address of the peer -
     *     when using NAN discovery use the alternative network specifier method -
     *     {@link WifiNanDiscoveryBaseSession#createNetworkSpecifier(int, int, byte[])}.
     *     {@link WifiNanDiscoveryBaseSession#createNetworkSpecifier(int, Object, byte[])}.
     *
     * @param role  The role of this device:
     *              {@link WifiNanManager#WIFI_NAN_DATA_PATH_ROLE_INITIATOR} or