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

Commit dadd3848 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by android-build-merger
Browse files

Merge "[AWARE] Implement custom Wi-Fi Aware network specifier" am: a9cbda5b am: 1d82eb06

am: 0d89fcc6

Change-Id: Ia6549a6fa404518d091ecb7bd74ece41f547d8c7
parents 1f59e1b2 0d89fcc6
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -26751,8 +26751,8 @@ package android.net.wifi.aware {
  }
  public class DiscoverySession {
    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 android.net.NetworkSpecifier createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle);
    method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
    method public void destroy();
    method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
  }
@@ -26838,8 +26838,8 @@ package android.net.wifi.aware {
  }
  public class WifiAwareSession {
    method public java.lang.String createNetworkSpecifierOpen(int, byte[]);
    method public java.lang.String createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
    method public android.net.NetworkSpecifier createNetworkSpecifierOpen(int, byte[]);
    method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
    method public void destroy();
    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);
+6 −6
Original line number Diff line number Diff line
@@ -29494,9 +29494,9 @@ package android.net.wifi.aware {
  }
  public class DiscoverySession {
    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 android.net.NetworkSpecifier createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle);
    method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
    method public android.net.NetworkSpecifier createNetworkSpecifierPmk(android.net.wifi.aware.PeerHandle, byte[]);
    method public void destroy();
    method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
  }
@@ -29582,9 +29582,9 @@ package android.net.wifi.aware {
  }
  public class WifiAwareSession {
    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 android.net.NetworkSpecifier createNetworkSpecifierOpen(int, byte[]);
    method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
    method public android.net.NetworkSpecifier createNetworkSpecifierPmk(int, byte[], byte[]);
    method public void destroy();
    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);
+4 −4
Original line number Diff line number Diff line
@@ -26858,8 +26858,8 @@ package android.net.wifi.aware {
  }
  public class DiscoverySession {
    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 android.net.NetworkSpecifier createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle);
    method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
    method public void destroy();
    method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
  }
@@ -26945,8 +26945,8 @@ package android.net.wifi.aware {
  }
  public class WifiAwareSession {
    method public java.lang.String createNetworkSpecifierOpen(int, byte[]);
    method public java.lang.String createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
    method public android.net.NetworkSpecifier createNetworkSpecifierOpen(int, byte[]);
    method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
    method public void destroy();
    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);
+17 −16
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.net.wifi.aware;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.NetworkSpecifier;
import android.net.wifi.RttManager;
import android.util.Log;

@@ -250,8 +251,8 @@ public class DiscoverySession {
    }

    /**
     * Create a {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} for an
     * unencrypted WiFi Aware connection (link) to the specified peer. The
     * Create a {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(NetworkSpecifier)} for
     * an unencrypted WiFi Aware connection (link) to the specified peer. The
     * {@link android.net.NetworkRequest.Builder#addTransportType(int)} should be set to
     * {@link android.net.NetworkCapabilities#TRANSPORT_WIFI_AWARE}.
     * <p>
@@ -276,13 +277,13 @@ public class DiscoverySession {
     *                   request from only that peer. A RESPONDER may specify a {@code null} -
     *                   indicating that it will accept connection requests from any device.
     *
     * @return A string to be used to construct
     * {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to pass to
     * @return A {@link NetworkSpecifier} to be used to construct
     * {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(NetworkSpecifier)} to pass to
     * {@link android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest,
     * android.net.ConnectivityManager.NetworkCallback)}
     * [or other varieties of that API].
     */
    public String createNetworkSpecifierOpen(@Nullable PeerHandle peerHandle) {
    public NetworkSpecifier createNetworkSpecifierOpen(@Nullable PeerHandle peerHandle) {
        if (mTerminated) {
            Log.w(TAG, "createNetworkSpecifierOpen: called on terminated session");
            return null;
@@ -302,8 +303,8 @@ public class DiscoverySession {
    }

    /**
     * Create a {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} for an
     * encrypted WiFi Aware connection (link) to the specified peer. The
     * Create a {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(NetworkSpecifier)} for
     * an encrypted WiFi Aware connection (link) to the specified peer. The
     * {@link android.net.NetworkRequest.Builder#addTransportType(int)} should be set to
     * {@link android.net.NetworkCapabilities#TRANSPORT_WIFI_AWARE}.
     * <p>
@@ -329,14 +330,14 @@ public class DiscoverySession {
     *                   {@link #createNetworkSpecifierOpen(PeerHandle)} API to
     *                   specify an open (unencrypted) link.
     *
     * @return A string to be used to construct
     * {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to pass to
     * @return A {@link NetworkSpecifier} to be used to construct
     * {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(NetworkSpecifier)} to pass to
     * {@link android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest,
     * android.net.ConnectivityManager.NetworkCallback)}
     * [or other varieties of that API].
     */
    public String createNetworkSpecifierPassphrase(@Nullable PeerHandle peerHandle,
            @NonNull String passphrase) {
    public NetworkSpecifier createNetworkSpecifierPassphrase(
            @Nullable PeerHandle peerHandle, @NonNull String passphrase) {
        if (passphrase == null || passphrase.length() == 0) {
            throw new IllegalArgumentException("Passphrase must not be null or empty");
        }
@@ -361,8 +362,8 @@ public class DiscoverySession {
    }

    /**
     * Create a {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} for an
     * encrypted WiFi Aware connection (link) to the specified peer. The
     * Create a {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(NetworkSpecifier)} for
     * an encrypted WiFi Aware connection (link) to the specified peer. The
     * {@link android.net.NetworkRequest.Builder#addTransportType(int)} should be set to
     * {@link android.net.NetworkCapabilities#TRANSPORT_WIFI_AWARE}.
     * <p>
@@ -389,8 +390,8 @@ public class DiscoverySession {
     *            Passphrase or {@link #createNetworkSpecifierOpen(PeerHandle)} to specify an
     *            open (unencrypted) link.
     *
     * @return A string to be used to construct
     * {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to pass to
     * @return A {@link NetworkSpecifier} to be used to construct
     * {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(NetworkSpecifier)} to pass to
     * {@link android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest,
     * android.net.ConnectivityManager.NetworkCallback)}
     * [or other varieties of that API].
@@ -398,7 +399,7 @@ public class DiscoverySession {
     * @hide
     */
    @SystemApi
    public String createNetworkSpecifierPmk(@Nullable PeerHandle peerHandle,
    public NetworkSpecifier createNetworkSpecifierPmk(@Nullable PeerHandle peerHandle,
            @NonNull byte[] pmk) {
        if (pmk == null || pmk.length == 0) {
            throw new IllegalArgumentException("PMK must not be null or empty");
+23 −119
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkRequest;
import android.net.NetworkSpecifier;
import android.net.wifi.RttManager;
import android.os.Binder;
import android.os.Bundle;
@@ -31,7 +32,6 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.util.Base64;
import android.util.Log;
import android.util.SparseArray;

@@ -39,9 +39,6 @@ import com.android.internal.annotations.GuardedBy;

import libcore.util.HexEncoding;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
@@ -128,65 +125,6 @@ public class WifiAwareManager {
    private static final boolean DBG = false;
    private static final boolean VDBG = false; // STOPSHIP if true

    /**
     * Keys used to generate a Network Specifier for the Aware network request. The network
     * specifier is formatted as a JSON string.
     */

    /**
     * TYPE: in band, specific peer: role, client_id, session_id, peer_id, pmk/passphrase optional
     * @hide
     */
    public static final int NETWORK_SPECIFIER_TYPE_IB = 0;

    /**
     * TYPE: in band, any peer: role, client_id, session_id, pmk/passphrase optional
     * [only permitted for RESPONDER]
     * @hide
     */
    public static final int NETWORK_SPECIFIER_TYPE_IB_ANY_PEER = 1;

    /**
     * TYPE: out-of-band: role, client_id, peer_mac, pmk/passphrase optional
     * @hide
     */
    public static final int NETWORK_SPECIFIER_TYPE_OOB = 2;

    /**
     * TYPE: out-of-band, any peer: role, client_id, pmk/passphrase optional
     * [only permitted for RESPONDER]
     * @hide
     */
    public static final int NETWORK_SPECIFIER_TYPE_OOB_ANY_PEER = 3;


    /** @hide */
    public static final int NETWORK_SPECIFIER_TYPE_MAX_VALID = NETWORK_SPECIFIER_TYPE_OOB_ANY_PEER;

    /** @hide */
    public static final String NETWORK_SPECIFIER_KEY_TYPE = "type";

    /** @hide */
    public static final String NETWORK_SPECIFIER_KEY_ROLE = "role";

    /** @hide */
    public static final String NETWORK_SPECIFIER_KEY_CLIENT_ID = "client_id";

    /** @hide */
    public static final String NETWORK_SPECIFIER_KEY_SESSION_ID = "session_id";

    /** @hide */
    public static final String NETWORK_SPECIFIER_KEY_PEER_ID = "peer_id";

    /** @hide */
    public static final String NETWORK_SPECIFIER_KEY_PEER_MAC = "peer_mac";

    /** @hide */
    public static final String NETWORK_SPECIFIER_KEY_PMK = "pmk";

    /** @hide */
    public static final String NETWORK_SPECIFIER_KEY_PASSPHRASE = "passphrase";

    /**
     * Broadcast intent action to indicate that the state of Wi-Fi Aware availability has changed.
     * Use the {@link #isAvailable()} to query the current status.
@@ -483,7 +421,7 @@ public class WifiAwareManager {
    }

    /** @hide */
    public String createNetworkSpecifier(int clientId, int role, int sessionId,
    public NetworkSpecifier createNetworkSpecifier(int clientId, int role, int sessionId,
            PeerHandle peerHandle, @Nullable byte[] pmk, @Nullable String passphrase) {
        if (VDBG) {
            Log.v(TAG, "createNetworkSpecifier: role=" + role + ", sessionId=" + sessionId
@@ -492,9 +430,6 @@ public class WifiAwareManager {
                    + ", passphrase=" + ((passphrase == null) ? "null" : "non-null"));
        }

        int type = (peerHandle == null) ? NETWORK_SPECIFIER_TYPE_IB_ANY_PEER
                : NETWORK_SPECIFIER_TYPE_IB;

        if (role != WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
                && role != WIFI_AWARE_DATA_PATH_ROLE_RESPONDER) {
            throw new IllegalArgumentException(
@@ -509,35 +444,20 @@ public class WifiAwareManager {
            }
        }

        JSONObject json;
        try {
            json = new JSONObject();
            json.put(NETWORK_SPECIFIER_KEY_TYPE, type);
            json.put(NETWORK_SPECIFIER_KEY_ROLE, role);
            json.put(NETWORK_SPECIFIER_KEY_CLIENT_ID, clientId);
            json.put(NETWORK_SPECIFIER_KEY_SESSION_ID, sessionId);
            if (peerHandle != null) {
                json.put(NETWORK_SPECIFIER_KEY_PEER_ID, peerHandle.peerId);
            }
            if (pmk == null) {
                pmk = new byte[0];
            }
            json.put(NETWORK_SPECIFIER_KEY_PMK,
                    Base64.encodeToString(pmk, 0, pmk.length, Base64.DEFAULT));
            if (passphrase == null) {
                passphrase = new String();
            }
            json.put(NETWORK_SPECIFIER_KEY_PASSPHRASE, passphrase);

        } catch (JSONException e) {
            return "";
        }

        return json.toString();
        return new WifiAwareNetworkSpecifier(
                (peerHandle == null) ? WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_IB_ANY_PEER
                        : WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_IB,
                role,
                clientId,
                sessionId,
                peerHandle != null ? peerHandle.peerId : 0, // 0 is an invalid peer ID
                null, // peerMac (not used in this method)
                pmk,
                passphrase);
    }

    /** @hide */
    public String createNetworkSpecifier(int clientId, @DataPathRole int role,
    public NetworkSpecifier createNetworkSpecifier(int clientId, @DataPathRole int role,
            @Nullable byte[] peer, @Nullable byte[] pmk, @Nullable String passphrase) {
        if (VDBG) {
            Log.v(TAG, "createNetworkSpecifier: role=" + role
@@ -545,9 +465,6 @@ public class WifiAwareManager {
                    + ", passphrase=" + ((passphrase == null) ? "null" : "non-null"));
        }

        int type = (peer == null) ?
                NETWORK_SPECIFIER_TYPE_OOB_ANY_PEER : NETWORK_SPECIFIER_TYPE_OOB;

        if (role != WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
                && role != WIFI_AWARE_DATA_PATH_ROLE_RESPONDER) {
            throw new IllegalArgumentException(
@@ -564,29 +481,16 @@ public class WifiAwareManager {
            throw new IllegalArgumentException("createNetworkSpecifier: Invalid peer MAC address");
        }

        JSONObject json;
        try {
            json = new JSONObject();
            json.put(NETWORK_SPECIFIER_KEY_TYPE, type);
            json.put(NETWORK_SPECIFIER_KEY_ROLE, role);
            json.put(NETWORK_SPECIFIER_KEY_CLIENT_ID, clientId);
            if (peer != null) {
                json.put(NETWORK_SPECIFIER_KEY_PEER_MAC, new String(HexEncoding.encode(peer)));
            }
            if (pmk == null) {
                pmk = new byte[0];
            }
            json.put(NETWORK_SPECIFIER_KEY_PMK,
                    Base64.encodeToString(pmk, 0, pmk.length, Base64.DEFAULT));
            if (passphrase == null) {
                passphrase = new String();
            }
            json.put(NETWORK_SPECIFIER_KEY_PASSPHRASE, passphrase);
        } catch (JSONException e) {
            return "";
        }

        return json.toString();
        return new WifiAwareNetworkSpecifier(
                (peer == null) ? WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_OOB_ANY_PEER
                        : WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_OOB,
                role,
                clientId,
                0, // 0 is an invalid session ID
                0, // 0 is an invalid peer ID
                peer,
                pmk,
                passphrase);
    }

    private static class WifiAwareEventCallbackProxy extends IWifiAwareEventCallback.Stub {
Loading