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

Commit 9a26e434 authored by Etan Cohen's avatar Etan Cohen Committed by android-build-merger
Browse files

Merge "[AWARE] Simplify Wi-Fi Aware API namespace" am: 834a87d5 am: fd234214 am: 0bad91b5

am: 0232d188

Change-Id: Ibdb559206159eb840810f55f51545cdc797d16d6
parents 8d729e8c 0232d188
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -18,16 +18,16 @@ 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(WifiAwareAttachCallback, android.os.Handler)}. These are callbacks
 * {@link WifiAwareManager#attach(AttachCallback, 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 DiscoverySessionCallback}.
 *
 *
 * @hide PROPOSED_AWARE_API
 * @hide PROPOSED_AWARE_API
 */
 */
public class WifiAwareAttachCallback {
public class AttachCallback {
    /**
    /**
     * Called when Aware attach operation
     * Called when Aware attach operation
     * {@link WifiAwareManager#attach(WifiAwareAttachCallback, android.os.Handler)}
     * {@link WifiAwareManager#attach(AttachCallback, 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(WifiAwareAttachCallback, android.os.Handler)} failed.
     * {@link WifiAwareManager#attach(AttachCallback, android.os.Handler)} failed.
     */
     */
    public void onAttachFailed() {
    public void onAttachFailed() {
        /* empty */
        /* empty */
+1 −1
Original line number Original line Diff line number Diff line
@@ -16,4 +16,4 @@


package android.net.wifi.aware;
package android.net.wifi.aware;


parcelable WifiAwareCharacteristics;
parcelable Characteristics;
+9 −9
Original line number Original line Diff line number Diff line
@@ -25,7 +25,7 @@ import android.os.Parcelable;
 *
 *
 * @hide PROPOSED_AWARE_API
 * @hide PROPOSED_AWARE_API
 */
 */
public class WifiAwareCharacteristics implements Parcelable {
public class Characteristics implements Parcelable {
    /** @hide */
    /** @hide */
    public static final String KEY_MAX_SERVICE_NAME_LENGTH = "key_max_service_name_length";
    public static final String KEY_MAX_SERVICE_NAME_LENGTH = "key_max_service_name_length";
    /** @hide */
    /** @hide */
@@ -37,7 +37,7 @@ public class WifiAwareCharacteristics implements Parcelable {
    private Bundle mCharacteristics = new Bundle();
    private Bundle mCharacteristics = new Bundle();


    /** @hide : should not be created by apps */
    /** @hide : should not be created by apps */
    public WifiAwareCharacteristics(Bundle characteristics) {
    public Characteristics(Bundle characteristics) {
        mCharacteristics = characteristics;
        mCharacteristics = characteristics;
    }
    }


@@ -58,7 +58,7 @@ 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(WifiAwareManager.PeerHandle, int, byte[])}
     * {@link DiscoverySession#sendMessage(PeerHandle, int, byte[])}
     * variants.
     * 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.
@@ -89,17 +89,17 @@ public class WifiAwareCharacteristics implements Parcelable {
        return 0;
        return 0;
    }
    }


    public static final Creator<WifiAwareCharacteristics> CREATOR =
    public static final Creator<Characteristics> CREATOR =
            new Creator<WifiAwareCharacteristics>() {
            new Creator<Characteristics>() {
                @Override
                @Override
                public WifiAwareCharacteristics createFromParcel(Parcel in) {
                public Characteristics createFromParcel(Parcel in) {
                    WifiAwareCharacteristics c = new WifiAwareCharacteristics(in.readBundle());
                    Characteristics c = new Characteristics(in.readBundle());
                    return c;
                    return c;
                }
                }


                @Override
                @Override
                public WifiAwareCharacteristics[] newArray(int size) {
                public Characteristics[] newArray(int size) {
                    return new WifiAwareCharacteristics[size];
                    return new Characteristics[size];
                }
                }
            };
            };
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@ import android.os.Parcelable;
/**
/**
 * Defines a request object to configure a Wi-Fi Aware network. Built using
 * Defines a request object to configure a Wi-Fi Aware network. Built using
 * {@link ConfigRequest.Builder}. Configuration is requested using
 * {@link ConfigRequest.Builder}. Configuration is requested using
 * {@link WifiAwareManager#attach(WifiAwareAttachCallback, android.os.Handler)}.
 * {@link WifiAwareManager#attach(AttachCallback, android.os.Handler)}.
 * Note that the actual achieved configuration may be different from the
 * Note that the actual achieved configuration may be different from the
 * requested configuration - since different applications may request different
 * requested configuration - since different applications may request different
 * configurations.
 * configurations.
+32 −32
Original line number Original line Diff line number Diff line
@@ -29,21 +29,21 @@ import java.lang.ref.WeakReference;
/**
/**
 * A class representing a single publish or subscribe Aware session. This object
 * A class representing a single publish or subscribe Aware session. This object
 * will not be created directly - only its child classes are available:
 * will not be created directly - only its child classes are available:
 * {@link WifiAwarePublishDiscoverySession} and {@link WifiAwareSubscribeDiscoverySession}. This
 * {@link PublishDiscoverySession} and {@link SubscribeDiscoverySession}. 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(WifiAwareManager.PeerHandle, int, byte[])} or
 *     <li>Sending messages: {@link #sendMessage(PeerHandle, int, byte[])} or
 *     {@link #sendMessage(WifiAwareManager.PeerHandle, int, byte[], int)} methods.
 *     {@link #sendMessage(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(WifiAwareManager.PeerHandle, byte[])}.
 *     {@link #createNetworkSpecifier(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.
 *
 *
 * @hide PROPOSED_AWARE_API
 * @hide PROPOSED_AWARE_API
 */
 */
public class WifiAwareDiscoveryBaseSession {
public class DiscoverySession {
    private static final String TAG = "WifiAwareDiscBaseSsn";
    private static final String TAG = "DiscoverySession";
    private static final boolean DBG = false;
    private static final boolean DBG = false;
    private static final boolean VDBG = false; // STOPSHIP if true
    private static final boolean VDBG = false; // STOPSHIP if true


@@ -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(WifiAwareManager.PeerHandle, int, byte[], int)}.
     * {@link #sendMessage(PeerHandle, int, byte[], int)}.
     *
     *
     * @return Maximum retry count when sending messages.
     * @return Maximum retry count when sending messages.
     */
     */
@@ -71,7 +71,7 @@ public class WifiAwareDiscoveryBaseSession {
    }
    }


    /** @hide */
    /** @hide */
    public WifiAwareDiscoveryBaseSession(WifiAwareManager manager, int clientId, int sessionId) {
    public DiscoverySession(WifiAwareManager manager, int clientId, int sessionId) {
        if (VDBG) {
        if (VDBG) {
            Log.v(TAG, "New discovery session created: manager=" + manager + ", clientId="
            Log.v(TAG, "New discovery session created: manager=" + manager + ", clientId="
                    + clientId + ", sessionId=" + sessionId);
                    + clientId + ", sessionId=" + sessionId);
@@ -93,7 +93,7 @@ public class WifiAwareDiscoveryBaseSession {
     *     This operation must be done on a session which is no longer needed. Otherwise system
     *     This operation must be done on a session which is no longer needed. Otherwise system
     *     resources will continue to be utilized until the application exits. The only
     *     resources will continue to be utilized until the application exits. The only
     *     exception is a session for which we received a termination callback,
     *     exception is a session for which we received a termination callback,
     *     {@link WifiAwareDiscoverySessionCallback#onSessionTerminated(int)}.
     *     {@link DiscoverySessionCallback#onSessionTerminated(int)}.
     */
     */
    public void destroy() {
    public void destroy() {
        WifiAwareManager mgr = mMgr.get();
        WifiAwareManager mgr = mMgr.get();
@@ -139,23 +139,23 @@ 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(WifiAwareManager.PeerHandle,
     * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle,
     * byte[], java.util.List)} event.
     * byte[], java.util.List)} 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 DiscoverySessionCallback} indicate message was transmitted successfully,
     *     {@link WifiAwareDiscoverySessionCallback#onMessageSendSucceeded(int)}, or transmission
     *     {@link DiscoverySessionCallback#onMessageSendSucceeded(int)}, or transmission
     *     failed (possibly after several retries) -
     *     failed (possibly after several retries) -
     *     {@link WifiAwareDiscoverySessionCallback#onMessageSendFailed(int)}.
     *     {@link DiscoverySessionCallback#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(WifiAwareManager.PeerHandle,
     *     {@link DiscoverySessionCallback#onMessageReceived(PeerHandle,
     *     byte[])}.
     *     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(WifiAwareManager.PeerHandle,
     * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle,
     * byte[], java.util.List)} or
     * byte[], java.util.List)} or
     * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle,
     * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle,
     * byte[])} events.
     * 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
@@ -167,7 +167,7 @@ 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 WifiAwareManager.PeerHandle peerHandle, int messageId,
    public void sendMessage(@NonNull PeerHandle peerHandle, int messageId,
            @Nullable byte[] message, 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");
@@ -186,25 +186,25 @@ 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(WifiAwareManager.PeerHandle,
     * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle,
     * byte[], java.util.List)} event.
     * byte[], java.util.List)} 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 DiscoverySessionCallback} indicate message was transmitted successfully,
     *     {@link WifiAwareDiscoverySessionCallback#onMessageSendSucceeded(int)}, or transmission
     *     {@link DiscoverySessionCallback#onMessageSendSucceeded(int)}, or transmission
     *     failed (possibly after several retries) -
     *     failed (possibly after several retries) -
     *     {@link WifiAwareDiscoverySessionCallback#onMessageSendFailed(int)}.
     *     {@link DiscoverySessionCallback#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(WifiAwareManager.PeerHandle,
     * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle,
     * byte[])}.
     * byte[])}.
     * Equivalent to {@link #sendMessage(WifiAwareManager.PeerHandle, int, byte[], int)}
     * Equivalent to {@link #sendMessage(PeerHandle, int, byte[], int)}
     * with a {@code retryCount} of 0.
     * 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(WifiAwareManager.PeerHandle,
     * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle,
     * byte[], java.util.List)} or
     * byte[], java.util.List)} or
     * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle,
     * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle,
     * byte[])} events.
     * 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
@@ -212,16 +212,16 @@ public class WifiAwareDiscoveryBaseSession {
     *                  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 WifiAwareManager.PeerHandle peerHandle, int messageId,
    public void sendMessage(@NonNull PeerHandle peerHandle, int messageId,
            @Nullable byte[] message) {
            @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(WifiAwareManager.PeerHandle,
     * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle,
     * byte[], java.util.List)} or
     * byte[], java.util.List)} or
     * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle,
     * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle,
     * byte[])} operation - can
     * 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.
     *
     *
@@ -265,9 +265,9 @@ public class WifiAwareDiscoveryBaseSession {
     * and a Publisher is a RESPONDER.
     * and a Publisher is a RESPONDER.
     *
     *
     * @param peerHandle The peer's handle obtained through
     * @param peerHandle The peer's handle obtained through
     * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle,
     * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle,
     * byte[], java.util.List)} or
     * byte[], java.util.List)} or
     * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.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 specified a null - indicating that
     *                   from only that peer. A RESPONDER may specified a null - indicating that
     *                   it will accept connection requests from any device.
     *                   it will accept connection requests from any device.
@@ -283,7 +283,7 @@ public class WifiAwareDiscoveryBaseSession {
     * android.net.ConnectivityManager.NetworkCallback)}
     * android.net.ConnectivityManager.NetworkCallback)}
     * [or other varieties of that API].
     * [or other varieties of that API].
     */
     */
    public String createNetworkSpecifier(@Nullable WifiAwareManager.PeerHandle peerHandle,
    public String createNetworkSpecifier(@Nullable PeerHandle peerHandle,
            @Nullable byte[] token) {
            @Nullable byte[] token) {
        if (mTerminated) {
        if (mTerminated) {
            Log.w(TAG, "createNetworkSpecifier: called on terminated session");
            Log.w(TAG, "createNetworkSpecifier: called on terminated session");
@@ -295,7 +295,7 @@ public class WifiAwareDiscoveryBaseSession {
                return null;
                return null;
            }
            }


            int role = this instanceof WifiAwareSubscribeDiscoverySession
            int role = this instanceof SubscribeDiscoverySession
                    ? WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
                    ? WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
                    : WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER;
                    : WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER;


Loading