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

Commit 3a764c19 authored by Etan Cohen's avatar Etan Cohen
Browse files

[AWARE] Update network API: make open/encrypted explicit

Replace the older (implicitly) open network with 3 network
creation APIs:
- Open
- Passphrase-based
- PMK (SystemApi only)

Bug: 26564544
Bug: 35702875
Test: unit tests and integration (sl4a) tests
Change-Id: I29a1d668d245853755cd2dfaaa6c65fbb43989f7
parent 769fa0c8
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -24981,7 +24981,8 @@ package android.net.wifi.aware {
  }
  }
  public class DiscoverySession {
  public class DiscoverySession {
    method public java.lang.String createNetworkSpecifier(android.net.wifi.aware.PeerHandle, byte[]);
    method public java.lang.String createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle);
    method public java.lang.String createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
    method public void destroy();
    method public void destroy();
    method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
    method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
  }
  }
@@ -25069,7 +25070,8 @@ package android.net.wifi.aware {
  }
  }
  public class WifiAwareSession {
  public class WifiAwareSession {
    method public java.lang.String createNetworkSpecifier(int, byte[], byte[]);
    method public java.lang.String createNetworkSpecifierOpen(int, byte[]);
    method public java.lang.String createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
    method public void destroy();
    method public void destroy();
    method public void publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
    method public void publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
    method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
    method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
+6 −2
Original line number Original line Diff line number Diff line
@@ -27539,7 +27539,9 @@ package android.net.wifi.aware {
  }
  }
  public class DiscoverySession {
  public class DiscoverySession {
    method public java.lang.String createNetworkSpecifier(android.net.wifi.aware.PeerHandle, byte[]);
    method public java.lang.String createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle);
    method public java.lang.String createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
    method public java.lang.String createNetworkSpecifierPmk(android.net.wifi.aware.PeerHandle, byte[]);
    method public void destroy();
    method public void destroy();
    method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
    method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
  }
  }
@@ -27627,7 +27629,9 @@ package android.net.wifi.aware {
  }
  }
  public class WifiAwareSession {
  public class WifiAwareSession {
    method public java.lang.String createNetworkSpecifier(int, byte[], byte[]);
    method public java.lang.String createNetworkSpecifierOpen(int, byte[]);
    method public java.lang.String createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
    method public java.lang.String createNetworkSpecifierPmk(int, byte[], byte[]);
    method public void destroy();
    method public void destroy();
    method public void publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
    method public void publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
    method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
    method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
+4 −2
Original line number Original line Diff line number Diff line
@@ -25054,7 +25054,8 @@ package android.net.wifi.aware {
  }
  }
  public class DiscoverySession {
  public class DiscoverySession {
    method public java.lang.String createNetworkSpecifier(android.net.wifi.aware.PeerHandle, byte[]);
    method public java.lang.String createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle);
    method public java.lang.String createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
    method public void destroy();
    method public void destroy();
    method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
    method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
  }
  }
@@ -25142,7 +25143,8 @@ package android.net.wifi.aware {
  }
  }
  public class WifiAwareSession {
  public class WifiAwareSession {
    method public java.lang.String createNetworkSpecifier(int, byte[], byte[]);
    method public java.lang.String createNetworkSpecifierOpen(int, byte[]);
    method public java.lang.String createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
    method public void destroy();
    method public void destroy();
    method public void publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
    method public void publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
    method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
    method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
+14 −39
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package android.net.wifi.aware;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.wifi.RttManager;
import android.net.wifi.RttManager;
import android.util.Log;
import android.util.Log;


@@ -33,7 +34,8 @@ import java.lang.ref.WeakReference;
 * <ul>
 * <ul>
 *     <li>Sending messages: {@link #sendMessage(PeerHandle, int, byte[])} method.
 *     <li>Sending messages: {@link #sendMessage(PeerHandle, int, byte[])} method.
 *     <li>Creating a network-specifier when requesting a Aware connection:
 *     <li>Creating a network-specifier when requesting a Aware connection:
 *     {@link #createNetworkSpecifier(PeerHandle, byte[])}.
 *     {@link #createNetworkSpecifierOpen(PeerHandle)} or
 *     {@link #createNetworkSpecifierPassphrase(PeerHandle, String)}.
 * </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.
@@ -255,7 +257,7 @@ public class DiscoverySession {
     * <p>
     * <p>
     * This method should be used when setting up a connection with a peer discovered through Aware
     * This method should be used when setting up a connection with a peer discovered through Aware
     * discovery or communication (in such scenarios the MAC address of the peer is shielded by
     * discovery or communication (in such scenarios the MAC address of the peer is shielded by
     * an opaque peer ID handle). If a Aware connection is needed to a peer discovered using other
     * an opaque peer ID handle). If an Aware connection is needed to a peer discovered using other
     * OOB (out-of-band) mechanism then use the alternative
     * OOB (out-of-band) mechanism then use the alternative
     * {@link WifiAwareSession#createNetworkSpecifierOpen(int, byte[])} method - which uses the
     * {@link WifiAwareSession#createNetworkSpecifierOpen(int, byte[])} method - which uses the
     * peer's MAC address.
     * peer's MAC address.
@@ -263,24 +265,22 @@ public class DiscoverySession {
     * Note: per the Wi-Fi Aware specification the roles are fixed - a Subscriber is an INITIATOR
     * Note: per the Wi-Fi Aware specification the roles are fixed - a Subscriber is an INITIATOR
     * and a Publisher is a RESPONDER.
     * and a Publisher is a RESPONDER.
     * <p>
     * <p>
     * To set up an encrypted link use the {@link #createNetworkSpecifierPmk(PeerHandle, byte[])}
     * To set up an encrypted link use the
     * or {@link #createNetworkSpecifierPassphrase(PeerHandle, String)} APIs.
     * {@link #createNetworkSpecifierPassphrase(PeerHandle, String)} API.
     *
     *
     * @param peerHandle The peer's handle obtained through
     * @param peerHandle The peer's handle obtained through
     * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle, byte[], java.util.List)}
     * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle, byte[], java.util.List)}
     *                   or
     *                   or
     *                   {@link DiscoverySessionCallback#onMessageReceived(PeerHandle, byte[])}.
     *                   {@link DiscoverySessionCallback#onMessageReceived(PeerHandle, byte[])}.
     *                   On a RESPONDER this value is used to gate the acceptance of a connection
     *                   On a RESPONDER this value is used to gate the acceptance of a connection
     *                   request from only that peer. A RESPONDER may specify a null - indicating
     *                   request from only that peer. A RESPONDER may specify a {@code null} -
     *                   that it will accept connection requests from any device.
     *                   indicating that it will accept connection requests from any device.
     *
     *
     * @return A string to be used to construct
     * @return A string to be used to construct
     * {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to pass to
     * {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to pass to
     * {@link android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest,
     * {@link android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest,
     * android.net.ConnectivityManager.NetworkCallback)}
     * android.net.ConnectivityManager.NetworkCallback)}
     * [or other varieties of that API].
     * [or other varieties of that API].
     *
     * @hide
     */
     */
    public String createNetworkSpecifierOpen(@Nullable PeerHandle peerHandle) {
    public String createNetworkSpecifierOpen(@Nullable PeerHandle peerHandle) {
        if (mTerminated) {
        if (mTerminated) {
@@ -309,7 +309,7 @@ public class DiscoverySession {
     * <p>
     * <p>
     * This method should be used when setting up a connection with a peer discovered through Aware
     * This method should be used when setting up a connection with a peer discovered through Aware
     * discovery or communication (in such scenarios the MAC address of the peer is shielded by
     * discovery or communication (in such scenarios the MAC address of the peer is shielded by
     * an opaque peer ID handle). If a Aware connection is needed to a peer discovered using other
     * an opaque peer ID handle). If an Aware connection is needed to a peer discovered using other
     * OOB (out-of-band) mechanism then use the alternative
     * OOB (out-of-band) mechanism then use the alternative
     * {@link WifiAwareSession#createNetworkSpecifierPassphrase(int, byte[], String)} method -
     * {@link WifiAwareSession#createNetworkSpecifierPassphrase(int, byte[], String)} method -
     * which uses the peer's MAC address.
     * which uses the peer's MAC address.
@@ -322,12 +322,11 @@ public class DiscoverySession {
     * byte[], java.util.List)} or
     * byte[], java.util.List)} or
     * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle,
     * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle,
     * byte[])}. On a RESPONDER this value is used to gate the acceptance of a connection request
     * byte[])}. On a RESPONDER this value is used to gate the acceptance of a connection request
     *                   from only that peer. A RESPONDER may specify a null - indicating that
     *                   from only that peer. A RESPONDER may specify a {@code null} - indicating
     *                   it will accept connection requests from any device.
     *                   that it will accept connection requests from any device.
     * @param passphrase The passphrase to be used to encrypt the link. The PMK is generated from
     * @param passphrase The passphrase to be used to encrypt the link. The PMK is generated from
     *                   the passphrase. Use the
     *                   the passphrase. Use the
     *                   {@link #createNetworkSpecifierPmk(PeerHandle, byte[])} to specify the
     *                   {@link #createNetworkSpecifierOpen(PeerHandle)} API to
     *                   PMK directly or {@link #createNetworkSpecifierOpen(PeerHandle)} to
     *                   specify an open (unencrypted) link.
     *                   specify an open (unencrypted) link.
     *
     *
     * @return A string to be used to construct
     * @return A string to be used to construct
@@ -335,8 +334,6 @@ public class DiscoverySession {
     * {@link android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest,
     * {@link android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest,
     * android.net.ConnectivityManager.NetworkCallback)}
     * android.net.ConnectivityManager.NetworkCallback)}
     * [or other varieties of that API].
     * [or other varieties of that API].
     *
     * * @hide
     */
     */
    public String createNetworkSpecifierPassphrase(@Nullable PeerHandle peerHandle,
    public String createNetworkSpecifierPassphrase(@Nullable PeerHandle peerHandle,
            @NonNull String passphrase) {
            @NonNull String passphrase) {
@@ -371,7 +368,7 @@ public class DiscoverySession {
     * <p>
     * <p>
     * This method should be used when setting up a connection with a peer discovered through Aware
     * This method should be used when setting up a connection with a peer discovered through Aware
     * discovery or communication (in such scenarios the MAC address of the peer is shielded by
     * discovery or communication (in such scenarios the MAC address of the peer is shielded by
     * an opaque peer ID handle). If a Aware connection is needed to a peer discovered using other
     * an opaque peer ID handle). If an Aware connection is needed to a peer discovered using other
     * OOB (out-of-band) mechanism then use the alternative
     * OOB (out-of-band) mechanism then use the alternative
     * {@link WifiAwareSession#createNetworkSpecifierPmk(int, byte[], byte[])} method - which uses
     * {@link WifiAwareSession#createNetworkSpecifierPmk(int, byte[], byte[])} method - which uses
     * the peer's MAC address.
     * the peer's MAC address.
@@ -400,6 +397,7 @@ public class DiscoverySession {
     *
     *
     * @hide
     * @hide
     */
     */
    @SystemApi
    public String createNetworkSpecifierPmk(@Nullable PeerHandle peerHandle,
    public String createNetworkSpecifierPmk(@Nullable PeerHandle peerHandle,
            @NonNull byte[] pmk) {
            @NonNull byte[] pmk) {
        if (pmk == null || pmk.length == 0) {
        if (pmk == null || pmk.length == 0) {
@@ -423,27 +421,4 @@ public class DiscoverySession {


        return mgr.createNetworkSpecifier(mClientId, role, mSessionId, peerHandle, pmk, null);
        return mgr.createNetworkSpecifier(mClientId, role, mSessionId, peerHandle, pmk, null);
    }
    }

    /**
     * Place-holder for {@code createNetworkSpecifierOpen(PeerHandle)}. Present to enable
     * development of replacements CL without causing an API change. Will be removed when new
     * APIs are exposed.
     *
     * @param peerHandle The peer's handle obtained through
     * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle,
     * byte[], java.util.List)} or
     * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle,
     * byte[])}. On a RESPONDER this value is used to gate the acceptance of a connection request
     *                   from only that peer. A RESPONDER may specify a null - indicating that
     *                   it will accept connection requests from any device.
     * @param token Deprecated and ignored.
     * @return A string to be used to construct
     * {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to pass to
     * {@link android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest,
     * android.net.ConnectivityManager.NetworkCallback)}
     * [or other varieties of that API].
     */
    public String createNetworkSpecifier(@Nullable PeerHandle peerHandle, @Nullable byte[] token) {
        return createNetworkSpecifierOpen(peerHandle);
    }
}
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -24,7 +24,8 @@ package android.net.wifi.aware;
 * your identity - e.g. by starting a discovery session. This actual MAC address of the
 * your identity - e.g. by starting a discovery session. This actual MAC address of the
 * interface may also be useful if the application uses alternative (non-Aware) discovery but needs
 * interface may also be useful if the application uses alternative (non-Aware) discovery but needs
 * to set up a Aware connection. The provided Aware discovery interface MAC address can then be used
 * to set up a Aware connection. The provided Aware discovery interface MAC address can then be used
 * in {@link WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])}.
 * in {@link WifiAwareSession#createNetworkSpecifierOpen(int, byte[])} or
 * {@link WifiAwareSession#createNetworkSpecifierPassphrase(int, byte[], String)}.
 */
 */
public class IdentityChangedListener {
public class IdentityChangedListener {
    /**
    /**
Loading