From 3de35a5e5573828838bfa6359a1ac1bf22b19303 Mon Sep 17 00:00:00 2001 From: Etan Cohen Date: Mon, 19 Dec 2016 15:54:51 -0800 Subject: [AWARE] Simplify Wi-Fi Aware API namespace Simplify Wi-fi Aware API namespace. Rely on project and remove WifiAware prefix from most classes. (pure rename operation: no functional changes) Bug: 31470256 Test: unit-tests + integration (sl4a) tests. Change-Id: I38b8137c1730c8f40c482c6770caafcaeafd5c46 --- .../android/net/wifi/aware/AttachCallback.java | 47 ++++ .../android/net/wifi/aware/Characteristics.aidl | 19 ++ .../android/net/wifi/aware/Characteristics.java | 105 +++++++ .../java/android/net/wifi/aware/ConfigRequest.java | 2 +- .../android/net/wifi/aware/DiscoverySession.java | 305 +++++++++++++++++++++ .../net/wifi/aware/DiscoverySessionCallback.java | 185 +++++++++++++ .../android/net/wifi/aware/IWifiAwareManager.aidl | 4 +- .../net/wifi/aware/IdentityChangedListener.java | 40 +++ wifi/java/android/net/wifi/aware/PeerHandle.java | 36 +++ .../java/android/net/wifi/aware/PublishConfig.java | 20 +- .../net/wifi/aware/PublishDiscoverySession.java | 70 +++++ .../android/net/wifi/aware/SubscribeConfig.java | 24 +- .../net/wifi/aware/SubscribeDiscoverySession.java | 75 +++++ .../net/wifi/aware/WifiAwareAttachCallback.java | 47 ---- .../net/wifi/aware/WifiAwareCharacteristics.aidl | 19 -- .../net/wifi/aware/WifiAwareCharacteristics.java | 105 ------- .../wifi/aware/WifiAwareDiscoveryBaseSession.java | 305 --------------------- .../aware/WifiAwareDiscoverySessionCallback.java | 185 ------------- .../aware/WifiAwareIdentityChangedListener.java | 40 --- .../android/net/wifi/aware/WifiAwareManager.java | 97 +++---- .../aware/WifiAwarePublishDiscoverySession.java | 70 ----- .../android/net/wifi/aware/WifiAwareSession.java | 36 +-- .../aware/WifiAwareSubscribeDiscoverySession.java | 75 ----- .../net/wifi/aware/WifiAwareManagerTest.java | 48 ++-- 24 files changed, 991 insertions(+), 968 deletions(-) create mode 100644 wifi/java/android/net/wifi/aware/AttachCallback.java create mode 100644 wifi/java/android/net/wifi/aware/Characteristics.aidl create mode 100644 wifi/java/android/net/wifi/aware/Characteristics.java create mode 100644 wifi/java/android/net/wifi/aware/DiscoverySession.java create mode 100644 wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java create mode 100644 wifi/java/android/net/wifi/aware/IdentityChangedListener.java create mode 100644 wifi/java/android/net/wifi/aware/PeerHandle.java create mode 100644 wifi/java/android/net/wifi/aware/PublishDiscoverySession.java create mode 100644 wifi/java/android/net/wifi/aware/SubscribeDiscoverySession.java delete mode 100644 wifi/java/android/net/wifi/aware/WifiAwareAttachCallback.java delete mode 100644 wifi/java/android/net/wifi/aware/WifiAwareCharacteristics.aidl delete mode 100644 wifi/java/android/net/wifi/aware/WifiAwareCharacteristics.java delete mode 100644 wifi/java/android/net/wifi/aware/WifiAwareDiscoveryBaseSession.java delete mode 100644 wifi/java/android/net/wifi/aware/WifiAwareDiscoverySessionCallback.java delete mode 100644 wifi/java/android/net/wifi/aware/WifiAwareIdentityChangedListener.java delete mode 100644 wifi/java/android/net/wifi/aware/WifiAwarePublishDiscoverySession.java delete mode 100644 wifi/java/android/net/wifi/aware/WifiAwareSubscribeDiscoverySession.java diff --git a/wifi/java/android/net/wifi/aware/AttachCallback.java b/wifi/java/android/net/wifi/aware/AttachCallback.java new file mode 100644 index 000000000000..90216f3f71d3 --- /dev/null +++ b/wifi/java/android/net/wifi/aware/AttachCallback.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.wifi.aware; + +/** + * Base class for Aware attach callbacks. Should be extended by applications and set when calling + * {@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 - + * for that see {@link DiscoverySessionCallback}. + * + * @hide PROPOSED_AWARE_API + */ +public class AttachCallback { + /** + * Called when Aware attach operation + * {@link WifiAwareManager#attach(AttachCallback, android.os.Handler)} + * 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. + * discovery, connections. + */ + public void onAttached(WifiAwareSession session) { + /* empty */ + } + + /** + * Called when Aware attach operation + * {@link WifiAwareManager#attach(AttachCallback, android.os.Handler)} failed. + */ + public void onAttachFailed() { + /* empty */ + } +} diff --git a/wifi/java/android/net/wifi/aware/Characteristics.aidl b/wifi/java/android/net/wifi/aware/Characteristics.aidl new file mode 100644 index 000000000000..77305e9dae0a --- /dev/null +++ b/wifi/java/android/net/wifi/aware/Characteristics.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.wifi.aware; + +parcelable Characteristics; diff --git a/wifi/java/android/net/wifi/aware/Characteristics.java b/wifi/java/android/net/wifi/aware/Characteristics.java new file mode 100644 index 000000000000..1c3e39025439 --- /dev/null +++ b/wifi/java/android/net/wifi/aware/Characteristics.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.wifi.aware; + +import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; + +/** + * The characteristics of the Wi-Fi Aware implementation. + * + * @hide PROPOSED_AWARE_API + */ +public class Characteristics implements Parcelable { + /** @hide */ + public static final String KEY_MAX_SERVICE_NAME_LENGTH = "key_max_service_name_length"; + /** @hide */ + public static final String KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH = + "key_max_service_specific_info_length"; + /** @hide */ + public static final String KEY_MAX_MATCH_FILTER_LENGTH = "key_max_match_filter_length"; + + private Bundle mCharacteristics = new Bundle(); + + /** @hide : should not be created by apps */ + public Characteristics(Bundle characteristics) { + mCharacteristics = characteristics; + } + + /** + * Returns the maximum string length that can be used to specify a Aware service name. Restricts + * the parameters of the {@link PublishConfig.Builder#setServiceName(String)} and + * {@link SubscribeConfig.Builder#setServiceName(String)}. + * + * @return A positive integer, maximum string length of Aware service name. + */ + public int getMaxServiceNameLength() { + return mCharacteristics.getInt(KEY_MAX_SERVICE_NAME_LENGTH); + } + + /** + * Returns the maximum length of byte array that can be used to specify a Aware service specific + * information field: the arbitrary load used in discovery or the message length of Aware + * message exchange. Restricts the parameters of the + * {@link PublishConfig.Builder#setServiceSpecificInfo(byte[])}, + * {@link SubscribeConfig.Builder#setServiceSpecificInfo(byte[])}, and + * {@link DiscoverySession#sendMessage(PeerHandle, int, byte[])} + * variants. + * + * @return A positive integer, maximum length of byte array for Aware messaging. + */ + public int getMaxServiceSpecificInfoLength() { + return mCharacteristics.getInt(KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH); + } + + /** + * Returns the maximum length of byte array that can be used to specify a Aware match filter. + * Restricts the parameters of the + * {@link PublishConfig.Builder#setMatchFilter(java.util.List)} and + * {@link SubscribeConfig.Builder#setMatchFilter(java.util.List)}. + * + * @return A positive integer, maximum legngth of byte array for Aware discovery match filter. + */ + public int getMaxMatchFilterLength() { + return mCharacteristics.getInt(KEY_MAX_MATCH_FILTER_LENGTH); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeBundle(mCharacteristics); + } + + @Override + public int describeContents() { + return 0; + } + + public static final Creator CREATOR = + new Creator() { + @Override + public Characteristics createFromParcel(Parcel in) { + Characteristics c = new Characteristics(in.readBundle()); + return c; + } + + @Override + public Characteristics[] newArray(int size) { + return new Characteristics[size]; + } + }; +} diff --git a/wifi/java/android/net/wifi/aware/ConfigRequest.java b/wifi/java/android/net/wifi/aware/ConfigRequest.java index 4b21b15d4994..6a5957badafb 100644 --- a/wifi/java/android/net/wifi/aware/ConfigRequest.java +++ b/wifi/java/android/net/wifi/aware/ConfigRequest.java @@ -22,7 +22,7 @@ import android.os.Parcelable; /** * Defines a request object to configure a Wi-Fi Aware network. Built 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 * requested configuration - since different applications may request different * configurations. diff --git a/wifi/java/android/net/wifi/aware/DiscoverySession.java b/wifi/java/android/net/wifi/aware/DiscoverySession.java new file mode 100644 index 000000000000..e1bfd6546cb2 --- /dev/null +++ b/wifi/java/android/net/wifi/aware/DiscoverySession.java @@ -0,0 +1,305 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.wifi.aware; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.SystemApi; +import android.net.wifi.RttManager; +import android.util.Log; + +import dalvik.system.CloseGuard; + +import java.lang.ref.WeakReference; + +/** + * A class representing a single publish or subscribe Aware session. This object + * will not be created directly - only its child classes are available: + * {@link PublishDiscoverySession} and {@link SubscribeDiscoverySession}. This + * class provides functionality common to both publish and subscribe discovery sessions: + *
    + *
  • Sending messages: {@link #sendMessage(PeerHandle, int, byte[])} or + * {@link #sendMessage(PeerHandle, int, byte[], int)} methods. + *
  • Creating a network-specifier when requesting a Aware connection: + * {@link #createNetworkSpecifier(PeerHandle, byte[])}. + *
+ * The {@link #destroy()} method must be called to destroy discovery sessions once they are + * no longer needed. + * + * @hide PROPOSED_AWARE_API + */ +public class DiscoverySession { + private static final String TAG = "DiscoverySession"; + private static final boolean DBG = false; + private static final boolean VDBG = false; // STOPSHIP if true + + private static final int MAX_SEND_RETRY_COUNT = 5; + + /** @hide */ + protected WeakReference mMgr; + /** @hide */ + protected final int mClientId; + /** @hide */ + protected final int mSessionId; + /** @hide */ + protected boolean mTerminated = false; + + private final CloseGuard mCloseGuard = CloseGuard.get(); + + /** + * Return the maximum permitted retry count when sending messages using + * {@link #sendMessage(PeerHandle, int, byte[], int)}. + * + * @return Maximum retry count when sending messages. + */ + public static int getMaxSendRetryCount() { + return MAX_SEND_RETRY_COUNT; + } + + /** @hide */ + public DiscoverySession(WifiAwareManager manager, int clientId, int sessionId) { + if (VDBG) { + Log.v(TAG, "New discovery session created: manager=" + manager + ", clientId=" + + clientId + ", sessionId=" + sessionId); + } + + mMgr = new WeakReference<>(manager); + mClientId = clientId; + mSessionId = sessionId; + + mCloseGuard.open("destroy"); + } + + /** + * Destroy the publish or subscribe session - free any resources, and stop + * transmitting packets on-air (for an active session) or listening for + * matches (for a passive session). The session may not be used for any + * additional operations after its destruction. + *

+ * 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 + * exception is a session for which we received a termination callback, + * {@link DiscoverySessionCallback#onSessionTerminated(int)}. + */ + public void destroy() { + WifiAwareManager mgr = mMgr.get(); + if (mgr == null) { + Log.w(TAG, "destroy: called post GC on WifiAwareManager"); + return; + } + mgr.terminateSession(mClientId, mSessionId); + mTerminated = true; + mMgr.clear(); + mCloseGuard.close(); + } + + /** + * Sets the status of the session to terminated - i.e. an indication that + * already terminated rather than executing a termination. + * + * @hide + */ + public void setTerminated() { + if (mTerminated) { + Log.w(TAG, "terminate: already terminated."); + return; + } + mTerminated = true; + mMgr.clear(); + mCloseGuard.close(); + } + + /** @hide */ + @Override + protected void finalize() throws Throwable { + try { + if (!mTerminated) { + mCloseGuard.warnIfOpen(); + destroy(); + } + } finally { + super.finalize(); + } + } + + /** + * Sends a message to the specified destination. Aware messages are transmitted in the context + * of a discovery session - executed subsequent to a publish/subscribe + * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle, + * byte[], java.util.List)} event. + *

+ * Aware messages are not guaranteed delivery. Callbacks on + * {@link DiscoverySessionCallback} indicate message was transmitted successfully, + * {@link DiscoverySessionCallback#onMessageSendSucceeded(int)}, or transmission + * failed (possibly after several retries) - + * {@link DiscoverySessionCallback#onMessageSendFailed(int)}. + *

+ * The peer will get a callback indicating a message was received using + * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle, + * byte[])}. + * + * @param peerHandle The peer's handle for the message. Must be a result of an + * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle, + * byte[], java.util.List)} or + * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle, + * 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 Aware service - it + * can be arbitrary and non-unique. + * @param message The message to be transmitted. + * @param retryCount An integer specifying how many additional service-level (as opposed to PHY + * or MAC level) retries should be attempted if there is no ACK from the receiver + * (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(@NonNull PeerHandle peerHandle, int messageId, + @Nullable byte[] message, int retryCount) { + if (mTerminated) { + Log.w(TAG, "sendMessage: called on terminated session"); + return; + } else { + WifiAwareManager mgr = mMgr.get(); + if (mgr == null) { + Log.w(TAG, "sendMessage: called post GC on WifiAwareManager"); + return; + } + + mgr.sendMessage(mClientId, mSessionId, peerHandle, message, messageId, retryCount); + } + } + + /** + * Sends a message to the specified destination. Aware messages are transmitted in the context + * of a discovery session - executed subsequent to a publish/subscribe + * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle, + * byte[], java.util.List)} event. + *

+ * Aware messages are not guaranteed delivery. Callbacks on + * {@link DiscoverySessionCallback} indicate message was transmitted successfully, + * {@link DiscoverySessionCallback#onMessageSendSucceeded(int)}, or transmission + * failed (possibly after several retries) - + * {@link DiscoverySessionCallback#onMessageSendFailed(int)}. + *

+ * The peer will get a callback indicating a message was received using + * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle, + * byte[])}. + * Equivalent to {@link #sendMessage(PeerHandle, int, byte[], int)} + * with a {@code retryCount} of 0. + * + * @param peerHandle The peer's handle for the message. Must be a result of an + * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle, + * byte[], java.util.List)} or + * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle, + * 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 Aware service - it + * can be arbitrary and non-unique. + * @param message The message to be transmitted. + */ + public void sendMessage(@NonNull PeerHandle 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 DiscoverySessionCallback#onServiceDiscovered(PeerHandle, + * byte[], java.util.List)} or + * {@link DiscoverySessionCallback#onMessageReceived(PeerHandle, + * 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 + * {@link android.net.wifi.RttManager.RttParams#bssid} member must be set to + * a peer ID - not to a MAC address. + * @param listener The listener to receive the results of the ranging session. + * @hide PROPOSED_AWARE_SYSTEM_API + * [TODO: b/28847998 - track RTT API & visilibity] + */ + public void startRanging(RttManager.RttParams[] params, RttManager.RttListener listener) { + if (mTerminated) { + Log.w(TAG, "startRanging: called on terminated session"); + return; + } else { + WifiAwareManager mgr = mMgr.get(); + if (mgr == null) { + Log.w(TAG, "startRanging: called post GC on WifiAwareManager"); + return; + } + + mgr.startRanging(mClientId, mSessionId, params, listener); + } + } + + /** + * Create a {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} for a + * WiFi Aware connection to the specified peer. The + * {@link android.net.NetworkRequest.Builder#addTransportType(int)} should be set to + * {@link android.net.NetworkCapabilities#TRANSPORT_WIFI_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 + * an opaque peer ID handle). If a Aware connection is needed to a peer discovered using other + * OOB (out-of-band) mechanism then use the alternative + * {@link WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])} method - which uses the + * peer's MAC address. + *

+ * Note: per the Wi-Fi Aware specification the roles are fixed - a Subscriber is an INITIATOR + * and a Publisher is a RESPONDER. + * + * @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 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 + * on the RESPONDER and matches any peer token. An empty ({@code ""}) token is + * not the same as a null token and requires the peer token to be empty as well. + * + * @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) { + if (mTerminated) { + Log.w(TAG, "createNetworkSpecifier: called on terminated session"); + return null; + } else { + WifiAwareManager mgr = mMgr.get(); + if (mgr == null) { + Log.w(TAG, "createNetworkSpecifier: called post GC on WifiAwareManager"); + return null; + } + + int role = this instanceof SubscribeDiscoverySession + ? WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR + : WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER; + + return mgr.createNetworkSpecifier(mClientId, role, mSessionId, peerHandle, token); + } + } +} diff --git a/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java b/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java new file mode 100644 index 000000000000..f107ca80ce8f --- /dev/null +++ b/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.wifi.aware; + +import android.annotation.IntDef; +import android.annotation.NonNull; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.List; + +/** + * Base class for Aware session events callbacks. Should be extended by + * applications wanting notifications. The callbacks are set when a + * publish or subscribe session is created using + * {@link WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, + * android.os.Handler)} or + * {@link WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, + * android.os.Handler)}. + *

+ * A single callback is set at session creation - it cannot be replaced. + * + * @hide PROPOSED_AWARE_API + */ +public class DiscoverySessionCallback { + /** @hide */ + @IntDef({ + TERMINATE_REASON_DONE, TERMINATE_REASON_FAIL }) + @Retention(RetentionPolicy.SOURCE) + public @interface SessionTerminateCodes { + } + + /** + * Indicates that publish or subscribe session is done - all the + * requested operations (per {@link PublishConfig} or + * {@link SubscribeConfig}) have been executed. Failure reason flag for + * {@link DiscoverySessionCallback#onSessionTerminated(int)} callback. + */ + public static final int TERMINATE_REASON_DONE = 100; + + /** + * Indicates that publish or subscribe session is terminated due to a + * failure. + * Failure reason flag for + * {@link DiscoverySessionCallback#onSessionTerminated(int)} callback. + */ + public static final int TERMINATE_REASON_FAIL = 101; + + /** + * Called when a publish operation is started successfully in response to a + * {@link WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, + * android.os.Handler)} operation. + * + * @param session The {@link PublishDiscoverySession} used to control the + * discovery session. + */ + public void onPublishStarted(@NonNull PublishDiscoverySession session) { + /* empty */ + } + + /** + * Called when a subscribe operation is started successfully in response to a + * {@link WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, + * android.os.Handler)} operation. + * + * @param session The {@link SubscribeDiscoverySession} used to control the + * discovery session. + */ + public void onSubscribeStarted(@NonNull SubscribeDiscoverySession session) { + /* empty */ + } + + /** + * Called when a publish or subscribe discovery session configuration update request + * succeeds. Called in response to + * {@link PublishDiscoverySession#updatePublish(PublishConfig)} or + * {@link SubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. + */ + public void onSessionConfigUpdated() { + /* empty */ + } + + /** + * Called when a publish or subscribe discovery session cannot be created: + * {@link WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, + * android.os.Handler)} or + * {@link WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, + * android.os.Handler)}, or when a configuration update fails: + * {@link PublishDiscoverySession#updatePublish(PublishConfig)} or + * {@link SubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. + *

+ * For discovery session updates failure leaves the session running with its previous + * configuration - the discovery session is not terminated. + */ + public void onSessionConfigFailed() { + /* empty */ + } + + /** + * Called when a discovery session (publish or subscribe) terminates. Termination may be due + * to user-request (either directly through {@link DiscoverySession#destroy()} or + * application-specified expiration, e.g. {@link PublishConfig.Builder#setPublishCount(int)} + * or {@link SubscribeConfig.Builder#setTtlSec(int)}) or due to a failure. + * + * @param reason The termination reason using + * {@code DiscoverySessionCallback.TERMINATE_*} codes. + */ + public void onSessionTerminated(@SessionTerminateCodes int reason) { + /* empty */ + } + + /** + * Called when a discovery (publish or subscribe) operation results in a + * service discovery. + * + * @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 which resulted in this service discovery. + */ + public void onServiceDiscovered(PeerHandle peerHandle, + byte[] serviceSpecificInfo, List matchFilter) { + /* empty */ + } + + /** + * Called in response to + * {@link DiscoverySession#sendMessage(PeerHandle, int, byte[])} + * when a message is transmitted successfully - i.e. when it was received successfully by the + * peer (corresponds to an ACK being received). + *

+ * Note that either this callback or + * {@link DiscoverySessionCallback#onMessageSendFailed(int)} will be + * received - never both. + * + * @param messageId The arbitrary message ID specified when sending the message. + */ + public void onMessageSendSucceeded(@SuppressWarnings("unused") int messageId) { + /* empty */ + } + + /** + * 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 Aware stack (using + * the {@link DiscoverySession#sendMessage(PeerHandle, int, + * byte[], int)} method) - this event is received after all retries are exhausted. + *

+ * Note that either this callback or + * {@link DiscoverySessionCallback#onMessageSendSucceeded(int)} will be received + * - never both. + * + * @param messageId The arbitrary message ID specified when sending the message. + */ + public void onMessageSendFailed(@SuppressWarnings("unused") int messageId) { + /* empty */ + } + + /** + * Called when a message is received from a discovery session peer - in response to the + * peer's {@link DiscoverySession#sendMessage(PeerHandle, int, + * byte[])} or {@link DiscoverySession#sendMessage(PeerHandle, + * int, byte[], int)}. + * + * @param peerHandle An opaque handle to the peer matching our discovery operation. + * @param message A byte array containing the message. + */ + public void onMessageReceived(PeerHandle peerHandle, byte[] message) { + /* empty */ + } +} diff --git a/wifi/java/android/net/wifi/aware/IWifiAwareManager.aidl b/wifi/java/android/net/wifi/aware/IWifiAwareManager.aidl index 9c92807c63b5..794c142775f3 100644 --- a/wifi/java/android/net/wifi/aware/IWifiAwareManager.aidl +++ b/wifi/java/android/net/wifi/aware/IWifiAwareManager.aidl @@ -23,7 +23,7 @@ import android.net.wifi.aware.IWifiAwareDiscoverySessionCallback; import android.net.wifi.aware.IWifiAwareEventCallback; import android.net.wifi.aware.PublishConfig; import android.net.wifi.aware.SubscribeConfig; -import android.net.wifi.aware.WifiAwareCharacteristics; +import android.net.wifi.aware.Characteristics; import android.net.wifi.RttManager; /** @@ -37,7 +37,7 @@ interface IWifiAwareManager void enableUsage(); void disableUsage(); boolean isUsageEnabled(); - WifiAwareCharacteristics getCharacteristics(); + Characteristics getCharacteristics(); // client API void connect(in IBinder binder, in String callingPackage, in IWifiAwareEventCallback callback, diff --git a/wifi/java/android/net/wifi/aware/IdentityChangedListener.java b/wifi/java/android/net/wifi/aware/IdentityChangedListener.java new file mode 100644 index 000000000000..b0f97bda0339 --- /dev/null +++ b/wifi/java/android/net/wifi/aware/IdentityChangedListener.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.wifi.aware; + +/** + * Base class for a listener which is called with the MAC address of the Aware interface whenever + * it is changed. Change may be due to device joining a cluster, starting a cluster, or discovery + * interface change (addresses are randomized at regular intervals). The implication is that + * peers you've been communicating with may no longer recognize you and you need to re-establish + * 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 + * to set up a Aware connection. The provided Aware discovery interface MAC address can then be used + * in {@link WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])}. + * + * @hide PROPOSED_AWARE_API + */ +public class IdentityChangedListener { + /** + * @param mac The MAC address of the Aware discovery interface. The application must have the + * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} to get the actual MAC address, + * otherwise all 0's will be provided. + */ + public void onIdentityChanged(byte[] mac) { + /* empty */ + } +} diff --git a/wifi/java/android/net/wifi/aware/PeerHandle.java b/wifi/java/android/net/wifi/aware/PeerHandle.java new file mode 100644 index 000000000000..777d9a376fdf --- /dev/null +++ b/wifi/java/android/net/wifi/aware/PeerHandle.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.wifi.aware; + +/** + * Opaque object used to represent a Wi-Fi Aware peer. Obtained from discovery sessions in + * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle, byte[], java.util.List)}, used + * when sending messages e,g, {@link PublishDiscoverySession#sendMessage(PeerHandle, int, byte[])}, + * or when configuring a network link to a peer, e.g. + * {@link PublishDiscoverySession#createNetworkSpecifier(PeerHandle, byte[])}. + * + * @hide PROPOSED_AWARE_API + */ +public class PeerHandle { + /** @hide */ + public PeerHandle(int peerId) { + this.peerId = peerId; + } + + /** @hide */ + public int peerId; +} diff --git a/wifi/java/android/net/wifi/aware/PublishConfig.java b/wifi/java/android/net/wifi/aware/PublishConfig.java index 3925bd71ab9e..f218c086dfbb 100644 --- a/wifi/java/android/net/wifi/aware/PublishConfig.java +++ b/wifi/java/android/net/wifi/aware/PublishConfig.java @@ -33,9 +33,9 @@ import java.util.List; /** * Defines the configuration of a Aware publish session. Built using * {@link PublishConfig.Builder}. A publish session is created using - * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback, + * {@link WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, * android.os.Handler)} or updated using - * {@link WifiAwarePublishDiscoverySession#updatePublish(PublishConfig)}. + * {@link PublishDiscoverySession#updatePublish(PublishConfig)}. * * @hide PROPOSED_AWARE_API */ @@ -184,7 +184,7 @@ public final class PublishConfig implements Parcelable { * * @hide */ - public void assertValid(WifiAwareCharacteristics characteristics) + public void assertValid(Characteristics characteristics) throws IllegalArgumentException { WifiAwareUtils.validateServiceName(mServiceName); @@ -322,12 +322,12 @@ public final class PublishConfig implements Parcelable { * Sets the number of times an unsolicited (configured using * {@link PublishConfig.Builder#setPublishType(int)}) publish session * will be broadcast. When the count is reached an event will be - * generated for {@link WifiAwareDiscoverySessionCallback#onSessionTerminated(int)} - * with {@link WifiAwareDiscoverySessionCallback#TERMINATE_REASON_DONE} [unless + * generated for {@link DiscoverySessionCallback#onSessionTerminated(int)} + * with {@link DiscoverySessionCallback#TERMINATE_REASON_DONE} [unless * {@link #setTerminateNotificationEnabled(boolean)} disables the callback]. *

* Optional. 0 by default - indicating the session doesn't terminate on its own. - * Session will be terminated when {@link WifiAwareDiscoveryBaseSession#destroy()} is + * Session will be terminated when {@link DiscoverySession#destroy()} is * called. * * @param publishCount Number of publish packets to broadcast. @@ -348,12 +348,12 @@ public final class PublishConfig implements Parcelable { * {@link PublishConfig.Builder#setPublishType(int)}) publish session * will be alive - broadcasting a packet. When the TTL is reached * an event will be generated for - * {@link WifiAwareDiscoverySessionCallback#onSessionTerminated(int)} with - * {@link WifiAwareDiscoverySessionCallback#TERMINATE_REASON_DONE} [unless + * {@link DiscoverySessionCallback#onSessionTerminated(int)} with + * {@link DiscoverySessionCallback#TERMINATE_REASON_DONE} [unless * {@link #setTerminateNotificationEnabled(boolean)} disables the callback]. *

* Optional. 0 by default - indicating the session doesn't terminate on its own. - * Session will be terminated when {@link WifiAwareDiscoveryBaseSession#destroy()} is + * Session will be terminated when {@link DiscoverySession#destroy()} is * called. * * @param ttlSec Lifetime of a publish session in seconds. @@ -371,7 +371,7 @@ public final class PublishConfig implements Parcelable { /** * Configure whether a publish terminate notification - * {@link WifiAwareDiscoverySessionCallback#onSessionTerminated(int)} is reported + * {@link DiscoverySessionCallback#onSessionTerminated(int)} is reported * back to the callback. * * @param enable If true the terminate callback will be called when the diff --git a/wifi/java/android/net/wifi/aware/PublishDiscoverySession.java b/wifi/java/android/net/wifi/aware/PublishDiscoverySession.java new file mode 100644 index 000000000000..f2355b382e8d --- /dev/null +++ b/wifi/java/android/net/wifi/aware/PublishDiscoverySession.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.wifi.aware; + +import android.annotation.NonNull; +import android.util.Log; + +/** + * A class representing a Aware publish session. Created when + * {@link WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, + * android.os.Handler)} is called and a discovery session is created and returned in + * {@link DiscoverySessionCallback#onPublishStarted(PublishDiscoverySession)}. See + * baseline functionality of all discovery sessions in {@link DiscoverySession}. This + * object allows updating an existing/running publish discovery session using + * {@link #updatePublish(PublishConfig)}. + * + * @hide PROPOSED_AWARE_API + */ +public class PublishDiscoverySession extends DiscoverySession { + private static final String TAG = "PublishDiscoverySession"; + + /** @hide */ + public PublishDiscoverySession(WifiAwareManager manager, int clientId, int sessionId) { + super(manager, clientId, sessionId); + } + + /** + * Re-configure the currently active publish session. The + * {@link DiscoverySessionCallback} is not replaced - the same listener used + * at creation is still used. The results of the configuration are returned using + * {@link DiscoverySessionCallback}: + *

    + *
  • {@link DiscoverySessionCallback#onSessionConfigUpdated()}: configuration + * update succeeded. + *
  • {@link DiscoverySessionCallback#onSessionConfigFailed()}: configuration + * update failed. The publish discovery session is still running using its previous + * configuration (i.e. update failure does not terminate the session). + *
+ * + * @param publishConfig The new discovery publish session configuration ({@link PublishConfig}). + */ + public void updatePublish(@NonNull PublishConfig publishConfig) { + if (mTerminated) { + Log.w(TAG, "updatePublish: called on terminated session"); + return; + } else { + WifiAwareManager mgr = mMgr.get(); + if (mgr == null) { + Log.w(TAG, "updatePublish: called post GC on WifiAwareManager"); + return; + } + + mgr.updatePublish(mClientId, mSessionId, publishConfig); + } + } +} diff --git a/wifi/java/android/net/wifi/aware/SubscribeConfig.java b/wifi/java/android/net/wifi/aware/SubscribeConfig.java index 0fe69a81d218..7b91ea3eb5f4 100644 --- a/wifi/java/android/net/wifi/aware/SubscribeConfig.java +++ b/wifi/java/android/net/wifi/aware/SubscribeConfig.java @@ -33,9 +33,9 @@ import java.util.List; /** * Defines the configuration of a Aware subscribe session. Built using * {@link SubscribeConfig.Builder}. Subscribe is done using - * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback, + * {@link WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, * android.os.Handler)} or - * {@link WifiAwareSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. + * {@link SubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. * * @hide PROPOSED_AWARE_API */ @@ -212,7 +212,7 @@ public final class SubscribeConfig implements Parcelable { * * @hide */ - public void assertValid(WifiAwareCharacteristics characteristics) + public void assertValid(Characteristics characteristics) throws IllegalArgumentException { WifiAwareUtils.validateServiceName(mServiceName); @@ -355,11 +355,11 @@ public final class SubscribeConfig implements Parcelable { * Sets the number of times an active ( * {@link SubscribeConfig.Builder#setSubscribeType(int)}) subscribe session * will broadcast. When the count is reached an event will be - * generated for {@link WifiAwareDiscoverySessionCallback#onSessionTerminated(int)} - * with {@link WifiAwareDiscoverySessionCallback#TERMINATE_REASON_DONE}. + * generated for {@link DiscoverySessionCallback#onSessionTerminated(int)} + * with {@link DiscoverySessionCallback#TERMINATE_REASON_DONE}. *

* Optional. 0 by default - indicating the session doesn't terminate on its own. - * Session will be terminated when {@link WifiAwareDiscoveryBaseSession#destroy()} is + * Session will be terminated when {@link DiscoverySession#destroy()} is * called. * * @param subscribeCount Number of subscribe packets to broadcast. @@ -380,11 +380,11 @@ public final class SubscribeConfig implements Parcelable { * {@link SubscribeConfig.Builder#setSubscribeType(int)}) subscribe session * will be alive - i.e. broadcasting a packet. When the TTL is reached * an event will be generated for - * {@link WifiAwareDiscoverySessionCallback#onSessionTerminated(int)} with - * {@link WifiAwareDiscoverySessionCallback#TERMINATE_REASON_DONE}. + * {@link DiscoverySessionCallback#onSessionTerminated(int)} with + * {@link DiscoverySessionCallback#TERMINATE_REASON_DONE}. *

* Optional. 0 by default - indicating the session doesn't terminate on its own. - * Session will be terminated when {@link WifiAwareDiscoveryBaseSession#destroy()} is + * Session will be terminated when {@link DiscoverySession#destroy()} is * called. * * @param ttlSec Lifetime of a subscribe session in seconds. @@ -404,8 +404,8 @@ public final class SubscribeConfig implements Parcelable { * Sets the match style of the subscription - how are matches from a * single match session (corresponding to the same publish action on the * peer) reported to the host (using the - * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle, - * byte[], List)}). The options are: only report the first match and ignore the rest + * {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle, byte[], + * java.util.List)}). The options are: only report the first match and ignore the rest * {@link SubscribeConfig#MATCH_STYLE_FIRST_ONLY} or report every single * match {@link SubscribeConfig#MATCH_STYLE_ALL} (the default). * @@ -424,7 +424,7 @@ public final class SubscribeConfig implements Parcelable { /** * Configure whether a subscribe terminate notification - * {@link WifiAwareDiscoverySessionCallback#onSessionTerminated(int)} is reported + * {@link DiscoverySessionCallback#onSessionTerminated(int)} is reported * back to the callback. * * @param enable If true the terminate callback will be called when the diff --git a/wifi/java/android/net/wifi/aware/SubscribeDiscoverySession.java b/wifi/java/android/net/wifi/aware/SubscribeDiscoverySession.java new file mode 100644 index 000000000000..cf01f91872cf --- /dev/null +++ b/wifi/java/android/net/wifi/aware/SubscribeDiscoverySession.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.wifi.aware; + +import android.annotation.NonNull; +import android.util.Log; + +/** + * A class representing a Aware subscribe session. Created when + * {@link WifiAwareSession#subscribe(SubscribeConfig, + * DiscoverySessionCallback, android.os.Handler)} + * is called and a discovery session is created and returned in + * {@link DiscoverySessionCallback#onSubscribeStarted(SubscribeDiscoverySession)}. + * See baseline functionality of all discovery sessions in {@link DiscoverySession}. + * This object allows updating an existing/running subscribe discovery session using + * {@link #updateSubscribe(SubscribeConfig)}. + * + * @hide PROPOSED_AWARE_API + */ +public class SubscribeDiscoverySession extends DiscoverySession { + private static final String TAG = "SubscribeDiscoverySession"; + + /** + * {@hide} + */ + public SubscribeDiscoverySession(WifiAwareManager manager, int clientId, + int sessionId) { + super(manager, clientId, sessionId); + } + + /** + * Re-configure the currently active subscribe session. The + * {@link DiscoverySessionCallback} is not replaced - the same listener used + * at creation is still used. The results of the configuration are returned using + * {@link DiscoverySessionCallback}: + *

    + *
  • {@link DiscoverySessionCallback#onSessionConfigUpdated()}: configuration + * update succeeded. + *
  • {@link DiscoverySessionCallback#onSessionConfigFailed()}: configuration + * update failed. The subscribe discovery session is still running using its previous + * configuration (i.e. update failure does not terminate the session). + *
+ * + * @param subscribeConfig The new discovery subscribe session configuration + * ({@link SubscribeConfig}). + */ + public void updateSubscribe(@NonNull SubscribeConfig subscribeConfig) { + if (mTerminated) { + Log.w(TAG, "updateSubscribe: called on terminated session"); + return; + } else { + WifiAwareManager mgr = mMgr.get(); + if (mgr == null) { + Log.w(TAG, "updateSubscribe: called post GC on WifiAwareManager"); + return; + } + + mgr.updateSubscribe(mClientId, mSessionId, subscribeConfig); + } + } +} diff --git a/wifi/java/android/net/wifi/aware/WifiAwareAttachCallback.java b/wifi/java/android/net/wifi/aware/WifiAwareAttachCallback.java deleted file mode 100644 index 1e8dbd945b6e..000000000000 --- a/wifi/java/android/net/wifi/aware/WifiAwareAttachCallback.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.aware; - -/** - * 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 - * applying to the Aware connection as a whole - not to specific publish or subscribe sessions - - * for that see {@link WifiAwareDiscoverySessionCallback}. - * - * @hide PROPOSED_AWARE_API - */ -public class WifiAwareAttachCallback { - /** - * Called when Aware attach operation - * {@link WifiAwareManager#attach(WifiAwareAttachCallback, android.os.Handler)} - * 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. - * discovery, connections. - */ - public void onAttached(WifiAwareSession session) { - /* empty */ - } - - /** - * Called when Aware attach operation - * {@link WifiAwareManager#attach(WifiAwareAttachCallback, android.os.Handler)} failed. - */ - public void onAttachFailed() { - /* empty */ - } -} diff --git a/wifi/java/android/net/wifi/aware/WifiAwareCharacteristics.aidl b/wifi/java/android/net/wifi/aware/WifiAwareCharacteristics.aidl deleted file mode 100644 index a35e71dada09..000000000000 --- a/wifi/java/android/net/wifi/aware/WifiAwareCharacteristics.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.aware; - -parcelable WifiAwareCharacteristics; diff --git a/wifi/java/android/net/wifi/aware/WifiAwareCharacteristics.java b/wifi/java/android/net/wifi/aware/WifiAwareCharacteristics.java deleted file mode 100644 index 092aa341c9b3..000000000000 --- a/wifi/java/android/net/wifi/aware/WifiAwareCharacteristics.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.aware; - -import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; - -/** - * The characteristics of the Wi-Fi Aware implementation. - * - * @hide PROPOSED_AWARE_API - */ -public class WifiAwareCharacteristics implements Parcelable { - /** @hide */ - public static final String KEY_MAX_SERVICE_NAME_LENGTH = "key_max_service_name_length"; - /** @hide */ - public static final String KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH = - "key_max_service_specific_info_length"; - /** @hide */ - public static final String KEY_MAX_MATCH_FILTER_LENGTH = "key_max_match_filter_length"; - - private Bundle mCharacteristics = new Bundle(); - - /** @hide : should not be created by apps */ - public WifiAwareCharacteristics(Bundle characteristics) { - mCharacteristics = characteristics; - } - - /** - * Returns the maximum string length that can be used to specify a Aware service name. Restricts - * the parameters of the {@link PublishConfig.Builder#setServiceName(String)} and - * {@link SubscribeConfig.Builder#setServiceName(String)}. - * - * @return A positive integer, maximum string length of Aware service name. - */ - public int getMaxServiceNameLength() { - return mCharacteristics.getInt(KEY_MAX_SERVICE_NAME_LENGTH); - } - - /** - * Returns the maximum length of byte array that can be used to specify a Aware service specific - * information field: the arbitrary load used in discovery or the message length of Aware - * message exchange. Restricts the parameters of the - * {@link PublishConfig.Builder#setServiceSpecificInfo(byte[])}, - * {@link SubscribeConfig.Builder#setServiceSpecificInfo(byte[])}, and - * {@link WifiAwareDiscoveryBaseSession#sendMessage(WifiAwareManager.PeerHandle, int, byte[])} - * variants. - * - * @return A positive integer, maximum length of byte array for Aware messaging. - */ - public int getMaxServiceSpecificInfoLength() { - return mCharacteristics.getInt(KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH); - } - - /** - * Returns the maximum length of byte array that can be used to specify a Aware match filter. - * Restricts the parameters of the - * {@link PublishConfig.Builder#setMatchFilter(java.util.List)} and - * {@link SubscribeConfig.Builder#setMatchFilter(java.util.List)}. - * - * @return A positive integer, maximum legngth of byte array for Aware discovery match filter. - */ - public int getMaxMatchFilterLength() { - return mCharacteristics.getInt(KEY_MAX_MATCH_FILTER_LENGTH); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeBundle(mCharacteristics); - } - - @Override - public int describeContents() { - return 0; - } - - public static final Creator CREATOR = - new Creator() { - @Override - public WifiAwareCharacteristics createFromParcel(Parcel in) { - WifiAwareCharacteristics c = new WifiAwareCharacteristics(in.readBundle()); - return c; - } - - @Override - public WifiAwareCharacteristics[] newArray(int size) { - return new WifiAwareCharacteristics[size]; - } - }; -} diff --git a/wifi/java/android/net/wifi/aware/WifiAwareDiscoveryBaseSession.java b/wifi/java/android/net/wifi/aware/WifiAwareDiscoveryBaseSession.java deleted file mode 100644 index 2812ad4f147d..000000000000 --- a/wifi/java/android/net/wifi/aware/WifiAwareDiscoveryBaseSession.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.aware; - -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.annotation.SystemApi; -import android.net.wifi.RttManager; -import android.util.Log; - -import dalvik.system.CloseGuard; - -import java.lang.ref.WeakReference; - -/** - * A class representing a single publish or subscribe Aware session. This object - * will not be created directly - only its child classes are available: - * {@link WifiAwarePublishDiscoverySession} and {@link WifiAwareSubscribeDiscoverySession}. This - * class provides functionality common to both publish and subscribe discovery sessions: - *
    - *
  • Sending messages: {@link #sendMessage(WifiAwareManager.PeerHandle, int, byte[])} or - * {@link #sendMessage(WifiAwareManager.PeerHandle, int, byte[], int)} methods. - *
  • Creating a network-specifier when requesting a Aware connection: - * {@link #createNetworkSpecifier(WifiAwareManager.PeerHandle, byte[])}. - *
- * The {@link #destroy()} method must be called to destroy discovery sessions once they are - * no longer needed. - * - * @hide PROPOSED_AWARE_API - */ -public class WifiAwareDiscoveryBaseSession { - private static final String TAG = "WifiAwareDiscBaseSsn"; - private static final boolean DBG = false; - private static final boolean VDBG = false; // STOPSHIP if true - - private static final int MAX_SEND_RETRY_COUNT = 5; - - /** @hide */ - protected WeakReference mMgr; - /** @hide */ - protected final int mClientId; - /** @hide */ - protected final int mSessionId; - /** @hide */ - protected boolean mTerminated = false; - - private final CloseGuard mCloseGuard = CloseGuard.get(); - - /** - * Return the maximum permitted retry count when sending messages using - * {@link #sendMessage(WifiAwareManager.PeerHandle, int, byte[], int)}. - * - * @return Maximum retry count when sending messages. - */ - public static int getMaxSendRetryCount() { - return MAX_SEND_RETRY_COUNT; - } - - /** @hide */ - public WifiAwareDiscoveryBaseSession(WifiAwareManager manager, int clientId, int sessionId) { - if (VDBG) { - Log.v(TAG, "New discovery session created: manager=" + manager + ", clientId=" - + clientId + ", sessionId=" + sessionId); - } - - mMgr = new WeakReference<>(manager); - mClientId = clientId; - mSessionId = sessionId; - - mCloseGuard.open("destroy"); - } - - /** - * Destroy the publish or subscribe session - free any resources, and stop - * transmitting packets on-air (for an active session) or listening for - * matches (for a passive session). The session may not be used for any - * additional operations after its destruction. - *

- * 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 - * exception is a session for which we received a termination callback, - * {@link WifiAwareDiscoverySessionCallback#onSessionTerminated(int)}. - */ - public void destroy() { - WifiAwareManager mgr = mMgr.get(); - if (mgr == null) { - Log.w(TAG, "destroy: called post GC on WifiAwareManager"); - return; - } - mgr.terminateSession(mClientId, mSessionId); - mTerminated = true; - mMgr.clear(); - mCloseGuard.close(); - } - - /** - * Sets the status of the session to terminated - i.e. an indication that - * already terminated rather than executing a termination. - * - * @hide - */ - public void setTerminated() { - if (mTerminated) { - Log.w(TAG, "terminate: already terminated."); - return; - } - mTerminated = true; - mMgr.clear(); - mCloseGuard.close(); - } - - /** @hide */ - @Override - protected void finalize() throws Throwable { - try { - if (!mTerminated) { - mCloseGuard.warnIfOpen(); - destroy(); - } - } finally { - super.finalize(); - } - } - - /** - * Sends a message to the specified destination. Aware messages are transmitted in the context - * of a discovery session - executed subsequent to a publish/subscribe - * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle, - * byte[], java.util.List)} event. - *

- * Aware messages are not guaranteed delivery. Callbacks on - * {@link WifiAwareDiscoverySessionCallback} indicate message was transmitted successfully, - * {@link WifiAwareDiscoverySessionCallback#onMessageSendSucceeded(int)}, or transmission - * failed (possibly after several retries) - - * {@link WifiAwareDiscoverySessionCallback#onMessageSendFailed(int)}. - *

- * The peer will get a callback indicating a message was received using - * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle, - * byte[])}. - * - * @param peerHandle The peer's handle for the message. Must be a result of an - * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle, - * byte[], java.util.List)} or - * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle, - * 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 Aware service - it - * can be arbitrary and non-unique. - * @param message The message to be transmitted. - * @param retryCount An integer specifying how many additional service-level (as opposed to PHY - * or MAC level) retries should be attempted if there is no ACK from the receiver - * (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(@NonNull WifiAwareManager.PeerHandle peerHandle, int messageId, - @Nullable byte[] message, int retryCount) { - if (mTerminated) { - Log.w(TAG, "sendMessage: called on terminated session"); - return; - } else { - WifiAwareManager mgr = mMgr.get(); - if (mgr == null) { - Log.w(TAG, "sendMessage: called post GC on WifiAwareManager"); - return; - } - - mgr.sendMessage(mClientId, mSessionId, peerHandle, message, messageId, retryCount); - } - } - - /** - * Sends a message to the specified destination. Aware messages are transmitted in the context - * of a discovery session - executed subsequent to a publish/subscribe - * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle, - * byte[], java.util.List)} event. - *

- * Aware messages are not guaranteed delivery. Callbacks on - * {@link WifiAwareDiscoverySessionCallback} indicate message was transmitted successfully, - * {@link WifiAwareDiscoverySessionCallback#onMessageSendSucceeded(int)}, or transmission - * failed (possibly after several retries) - - * {@link WifiAwareDiscoverySessionCallback#onMessageSendFailed(int)}. - *

- * The peer will get a callback indicating a message was received using - * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle, - * byte[])}. - * Equivalent to {@link #sendMessage(WifiAwareManager.PeerHandle, int, byte[], int)} - * with a {@code retryCount} of 0. - * - * @param peerHandle The peer's handle for the message. Must be a result of an - * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle, - * byte[], java.util.List)} or - * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle, - * 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 Aware service - it - * can be arbitrary and non-unique. - * @param message The message to be transmitted. - */ - public void sendMessage(@NonNull WifiAwareManager.PeerHandle 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 WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle, - * byte[], java.util.List)} or - * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle, - * 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 - * {@link android.net.wifi.RttManager.RttParams#bssid} member must be set to - * a peer ID - not to a MAC address. - * @param listener The listener to receive the results of the ranging session. - * @hide PROPOSED_AWARE_SYSTEM_API - * [TODO: b/28847998 - track RTT API & visilibity] - */ - public void startRanging(RttManager.RttParams[] params, RttManager.RttListener listener) { - if (mTerminated) { - Log.w(TAG, "startRanging: called on terminated session"); - return; - } else { - WifiAwareManager mgr = mMgr.get(); - if (mgr == null) { - Log.w(TAG, "startRanging: called post GC on WifiAwareManager"); - return; - } - - mgr.startRanging(mClientId, mSessionId, params, listener); - } - } - - /** - * Create a {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} for a - * WiFi Aware connection to the specified peer. The - * {@link android.net.NetworkRequest.Builder#addTransportType(int)} should be set to - * {@link android.net.NetworkCapabilities#TRANSPORT_WIFI_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 - * an opaque peer ID handle). If a Aware connection is needed to a peer discovered using other - * OOB (out-of-band) mechanism then use the alternative - * {@link WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])} method - which uses the - * peer's MAC address. - *

- * Note: per the Wi-Fi Aware specification the roles are fixed - a Subscriber is an INITIATOR - * and a Publisher is a RESPONDER. - * - * @param peerHandle The peer's handle obtained through - * {@link WifiAwareDiscoverySessionCallback#onServiceDiscovered(WifiAwareManager.PeerHandle, - * byte[], java.util.List)} or - * {@link WifiAwareDiscoverySessionCallback#onMessageReceived(WifiAwareManager.PeerHandle, - * 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 - * on the RESPONDER and matches any peer token. An empty ({@code ""}) token is - * not the same as a null token and requires the peer token to be empty as well. - * - * @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 WifiAwareManager.PeerHandle peerHandle, - @Nullable byte[] token) { - if (mTerminated) { - Log.w(TAG, "createNetworkSpecifier: called on terminated session"); - return null; - } else { - WifiAwareManager mgr = mMgr.get(); - if (mgr == null) { - Log.w(TAG, "createNetworkSpecifier: called post GC on WifiAwareManager"); - return null; - } - - int role = this instanceof WifiAwareSubscribeDiscoverySession - ? WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR - : WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER; - - return mgr.createNetworkSpecifier(mClientId, role, mSessionId, peerHandle, token); - } - } -} diff --git a/wifi/java/android/net/wifi/aware/WifiAwareDiscoverySessionCallback.java b/wifi/java/android/net/wifi/aware/WifiAwareDiscoverySessionCallback.java deleted file mode 100644 index fdf0d013334d..000000000000 --- a/wifi/java/android/net/wifi/aware/WifiAwareDiscoverySessionCallback.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.aware; - -import android.annotation.IntDef; -import android.annotation.NonNull; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.util.List; - -/** - * Base class for Aware session events callbacks. Should be extended by - * applications wanting notifications. The callbacks are set when a - * publish or subscribe session is created using - * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback, - * android.os.Handler)} or - * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback, - * android.os.Handler)}. - *

- * A single callback is set at session creation - it cannot be replaced. - * - * @hide PROPOSED_AWARE_API - */ -public class WifiAwareDiscoverySessionCallback { - /** @hide */ - @IntDef({ - TERMINATE_REASON_DONE, TERMINATE_REASON_FAIL }) - @Retention(RetentionPolicy.SOURCE) - public @interface SessionTerminateCodes { - } - - /** - * Indicates that publish or subscribe session is done - all the - * requested operations (per {@link PublishConfig} or - * {@link SubscribeConfig}) have been executed. Failure reason flag for - * {@link WifiAwareDiscoverySessionCallback#onSessionTerminated(int)} callback. - */ - public static final int TERMINATE_REASON_DONE = 100; - - /** - * Indicates that publish or subscribe session is terminated due to a - * failure. - * Failure reason flag for - * {@link WifiAwareDiscoverySessionCallback#onSessionTerminated(int)} callback. - */ - public static final int TERMINATE_REASON_FAIL = 101; - - /** - * Called when a publish operation is started successfully in response to a - * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback, - * android.os.Handler)} operation. - * - * @param session The {@link WifiAwarePublishDiscoverySession} used to control the - * discovery session. - */ - public void onPublishStarted(@NonNull WifiAwarePublishDiscoverySession session) { - /* empty */ - } - - /** - * Called when a subscribe operation is started successfully in response to a - * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback, - * android.os.Handler)} operation. - * - * @param session The {@link WifiAwareSubscribeDiscoverySession} used to control the - * discovery session. - */ - public void onSubscribeStarted(@NonNull WifiAwareSubscribeDiscoverySession session) { - /* empty */ - } - - /** - * Called when a publish or subscribe discovery session configuration update request - * succeeds. Called in response to - * {@link WifiAwarePublishDiscoverySession#updatePublish(PublishConfig)} or - * {@link WifiAwareSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. - */ - public void onSessionConfigUpdated() { - /* empty */ - } - - /** - * Called when a publish or subscribe discovery session cannot be created: - * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback, - * android.os.Handler)} or - * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback, - * android.os.Handler)}, or when a configuration update fails: - * {@link WifiAwarePublishDiscoverySession#updatePublish(PublishConfig)} or - * {@link WifiAwareSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. - *

- * For discovery session updates failure leaves the session running with its previous - * configuration - the discovery session is not terminated. - */ - public void onSessionConfigFailed() { - /* empty */ - } - - /** - * Called when a discovery session (publish or subscribe) terminates. Termination may be due - * to user-request (either directly through {@link WifiAwareDiscoveryBaseSession#destroy()} or - * application-specified expiration, e.g. {@link PublishConfig.Builder#setPublishCount(int)} - * or {@link SubscribeConfig.Builder#setTtlSec(int)}) or due to a failure. - * - * @param reason The termination reason using - * {@code WifiAwareDiscoverySessionCallback.TERMINATE_*} codes. - */ - public void onSessionTerminated(@SessionTerminateCodes int reason) { - /* empty */ - } - - /** - * Called when a discovery (publish or subscribe) operation results in a - * service discovery. - * - * @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 which resulted in this service discovery. - */ - public void onServiceDiscovered(WifiAwareManager.PeerHandle peerHandle, - byte[] serviceSpecificInfo, List matchFilter) { - /* empty */ - } - - /** - * Called in response to - * {@link WifiAwareDiscoveryBaseSession#sendMessage(WifiAwareManager.PeerHandle, int, byte[])} - * when a message is transmitted successfully - i.e. when it was received successfully by the - * peer (corresponds to an ACK being received). - *

- * Note that either this callback or - * {@link WifiAwareDiscoverySessionCallback#onMessageSendFailed(int)} will be - * received - never both. - * - * @param messageId The arbitrary message ID specified when sending the message. - */ - public void onMessageSendSucceeded(@SuppressWarnings("unused") int messageId) { - /* empty */ - } - - /** - * 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 Aware stack (using - * the {@link WifiAwareDiscoveryBaseSession#sendMessage(WifiAwareManager.PeerHandle, int, - * byte[], int)} method) - this event is received after all retries are exhausted. - *

- * Note that either this callback or - * {@link WifiAwareDiscoverySessionCallback#onMessageSendSucceeded(int)} will be received - * - never both. - * - * @param messageId The arbitrary message ID specified when sending the message. - */ - public void onMessageSendFailed(@SuppressWarnings("unused") int messageId) { - /* empty */ - } - - /** - * Called when a message is received from a discovery session peer - in response to the - * peer's {@link WifiAwareDiscoveryBaseSession#sendMessage(WifiAwareManager.PeerHandle, int, - * byte[])} or {@link WifiAwareDiscoveryBaseSession#sendMessage(WifiAwareManager.PeerHandle, - * int, byte[], int)}. - * - * @param peerHandle An opaque handle to the peer matching our discovery operation. - * @param message A byte array containing the message. - */ - public void onMessageReceived(WifiAwareManager.PeerHandle peerHandle, byte[] message) { - /* empty */ - } -} diff --git a/wifi/java/android/net/wifi/aware/WifiAwareIdentityChangedListener.java b/wifi/java/android/net/wifi/aware/WifiAwareIdentityChangedListener.java deleted file mode 100644 index e8f52cd4bdeb..000000000000 --- a/wifi/java/android/net/wifi/aware/WifiAwareIdentityChangedListener.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.aware; - -/** - * Base class for a listener which is called with the MAC address of the Aware interface whenever - * it is changed. Change may be due to device joining a cluster, starting a cluster, or discovery - * interface change (addresses are randomized at regular intervals). The implication is that - * peers you've been communicating with may no longer recognize you and you need to re-establish - * 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 - * to set up a Aware connection. The provided Aware discovery interface MAC address can then be used - * in {@link WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])}. - * - * @hide PROPOSED_AWARE_API - */ -public class WifiAwareIdentityChangedListener { - /** - * @param mac The MAC address of the Aware discovery interface. The application must have the - * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} to get the actual MAC address, - * otherwise all 0's will be provided. - */ - public void onIdentityChanged(byte[] mac) { - /* empty */ - } -} diff --git a/wifi/java/android/net/wifi/aware/WifiAwareManager.java b/wifi/java/android/net/wifi/aware/WifiAwareManager.java index 029794dfa380..7a866ad38974 100644 --- a/wifi/java/android/net/wifi/aware/WifiAwareManager.java +++ b/wifi/java/android/net/wifi/aware/WifiAwareManager.java @@ -58,14 +58,14 @@ import java.util.List; * The class provides access to: *

    *
  • Initialize a Aware cluster (peer-to-peer synchronization). Refer to - * {@link #attach(WifiAwareAttachCallback, Handler)}. + * {@link #attach(AttachCallback, Handler)}. *
  • Create discovery sessions (publish or subscribe sessions). Refer to - * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback, Handler)} and - * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback, Handler)}. + * {@link WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, Handler)} and + * {@link WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, Handler)}. *
  • Create a Aware network specifier to be used with * {@link ConnectivityManager#requestNetwork(NetworkRequest, ConnectivityManager.NetworkCallback)} * to set-up a Aware connection with a peer. Refer to - * {@link WifiAwareDiscoveryBaseSession#createNetworkSpecifier(PeerHandle, byte[])} and + * {@link DiscoverySession#createNetworkSpecifier(PeerHandle, byte[])} and * {@link WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])}. *
*

@@ -75,37 +75,37 @@ import java.util.List; * broadcast. Note that this broadcast is not sticky - you should register for it and then * check the above API to avoid a race condition. *

- * An application must use {@link #attach(WifiAwareAttachCallback, Handler)} to initialize a + * An application must use {@link #attach(AttachCallback, Handler)} to initialize a * Aware cluster - before making any other Aware operation. Aware cluster membership is a * device-wide operation - the API guarantees that the device is in a cluster or joins a * Aware cluster (or starts one if none can be found). Information about attach success (or - * failure) are returned in callbacks of {@link WifiAwareAttachCallback}. Proceed with Aware + * failure) are returned in callbacks of {@link AttachCallback}. Proceed with Aware * discovery or connection setup only after receiving confirmation that Aware attach - * succeeded - {@link WifiAwareAttachCallback#onAttached(WifiAwareSession)}. When an + * succeeded - {@link AttachCallback#onAttached(WifiAwareSession)}. When an * application is finished using Aware it must use the * {@link WifiAwareSession#destroy()} API to indicate to the Aware service that the device * may detach from the Aware cluster. The device will actually disable Aware once the last * application detaches. *

* Once a Aware attach is confirmed use the - * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback, Handler)} + * {@link WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, Handler)} * or - * {@link WifiAwareSession#subscribe(SubscribeConfig, WifiAwareDiscoverySessionCallback, + * {@link WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, * Handler)} to create publish or subscribe Aware discovery sessions. Events are called on the - * provided callback object {@link WifiAwareDiscoverySessionCallback}. Specifically, the - * {@link WifiAwareDiscoverySessionCallback#onPublishStarted(WifiAwarePublishDiscoverySession)} + * provided callback object {@link DiscoverySessionCallback}. Specifically, the + * {@link DiscoverySessionCallback#onPublishStarted(PublishDiscoverySession)} * and - * {@link WifiAwareDiscoverySessionCallback#onSubscribeStarted( - * WifiAwareSubscribeDiscoverySession)} - * return {@link WifiAwarePublishDiscoverySession} and - * {@link WifiAwareSubscribeDiscoverySession} + * {@link DiscoverySessionCallback#onSubscribeStarted( + *SubscribeDiscoverySession)} + * return {@link PublishDiscoverySession} and + * {@link SubscribeDiscoverySession} * objects respectively on which additional session operations can be performed, e.g. updating - * the session {@link WifiAwarePublishDiscoverySession#updatePublish(PublishConfig)} and - * {@link WifiAwareSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. Sessions can + * the session {@link PublishDiscoverySession#updatePublish(PublishConfig)} and + * {@link SubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. Sessions can * also be used to send messages using the - * {@link WifiAwareDiscoveryBaseSession#sendMessage(PeerHandle, int, byte[])} APIs. When an + * {@link DiscoverySession#sendMessage(PeerHandle, int, byte[])} APIs. When an * application is finished with a discovery session it must terminate it using the - * {@link WifiAwareDiscoveryBaseSession#destroy()} API. + * {@link DiscoverySession#destroy()} API. *

* Creating connections between Aware devices is managed by the standard * {@link ConnectivityManager#requestNetwork(NetworkRequest, @@ -116,7 +116,7 @@ import java.util.List; * {@link android.net.NetworkCapabilities#TRANSPORT_WIFI_AWARE}. *

  • {@link NetworkRequest.Builder#setNetworkSpecifier(String)} using * {@link WifiAwareSession#createNetworkSpecifier(int, byte[], byte[])} or - * {@link WifiAwareDiscoveryBaseSession#createNetworkSpecifier(PeerHandle, byte[])}. + * {@link DiscoverySession#createNetworkSpecifier(PeerHandle, byte[])}. * * * @hide PROPOSED_AWARE_API @@ -226,7 +226,7 @@ public class WifiAwareManager { * Connection creation role is that of INITIATOR. Used to create a network specifier string * when requesting a Aware network. * - * @see WifiAwareDiscoveryBaseSession#createNetworkSpecifier(PeerHandle, byte[]) + * @see DiscoverySession#createNetworkSpecifier(PeerHandle, byte[]) * @see WifiAwareSession#createNetworkSpecifier(int, byte[], byte[]) */ public static final int WIFI_AWARE_DATA_PATH_ROLE_INITIATOR = 0; @@ -235,7 +235,7 @@ public class WifiAwareManager { * Connection creation role is that of RESPONDER. Used to create a network specifier string * when requesting a Aware network. * - * @see WifiAwareDiscoveryBaseSession#createNetworkSpecifier(PeerHandle, byte[]) + * @see DiscoverySession#createNetworkSpecifier(PeerHandle, byte[]) * @see WifiAwareSession#createNetworkSpecifier(int, byte[], byte[]) */ public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1; @@ -307,7 +307,7 @@ public class WifiAwareManager { * @return An object specifying configuration limitations of Aware. * @hide PROPOSED_AWARE_API */ - public WifiAwareCharacteristics getCharacteristics() { + public Characteristics getCharacteristics() { try { return mService.getCharacteristics(); } catch (RemoteException e) { @@ -328,12 +328,12 @@ public class WifiAwareManager { * attachCallback}. * * @param attachCallback A callback for attach events, extended from - * {@link WifiAwareAttachCallback}. + * {@link AttachCallback}. * @param handler The Handler on whose thread to execute the callbacks of the {@code * attachCallback} object. If a null is provided then the application's main thread will be * used. */ - public void attach(@NonNull WifiAwareAttachCallback attachCallback, @Nullable Handler handler) { + public void attach(@NonNull AttachCallback attachCallback, @Nullable Handler handler) { attach(handler, null, attachCallback, null); } @@ -353,28 +353,28 @@ public class WifiAwareManager { * on startup and whenever it is updated (it is randomized at regular intervals for privacy). * The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} * permission to execute this attach request. Otherwise, use the - * {@link #attach(WifiAwareAttachCallback, Handler)} version. Note that aside from permission + * {@link #attach(AttachCallback, Handler)} version. Note that aside from permission * requirements this listener will wake up the host at regular intervals causing higher power * consumption, do not use it unless the information is necessary (e.g. for OOB discovery). * * @param attachCallback A callback for attach events, extended from - * {@link WifiAwareAttachCallback}. + * {@link AttachCallback}. * @param identityChangedListener A listener for changed identity, extended from - * {@link WifiAwareIdentityChangedListener}. + * {@link IdentityChangedListener}. * @param handler The Handler on whose thread to execute the callbacks of the {@code * attachCallback} and {@code identityChangedListener} objects. If a null is provided then the * application's main thread will be used. */ - public void attach(@NonNull WifiAwareAttachCallback attachCallback, - @NonNull WifiAwareIdentityChangedListener identityChangedListener, + public void attach(@NonNull AttachCallback attachCallback, + @NonNull IdentityChangedListener identityChangedListener, @Nullable Handler handler) { attach(handler, null, attachCallback, identityChangedListener); } /** @hide */ public void attach(Handler handler, ConfigRequest configRequest, - WifiAwareAttachCallback attachCallback, - WifiAwareIdentityChangedListener identityChangedListener) { + AttachCallback attachCallback, + IdentityChangedListener identityChangedListener) { if (VDBG) { Log.v(TAG, "attach(): handler=" + handler + ", callback=" + attachCallback + ", configRequest=" + configRequest + ", identityChangedListener=" @@ -409,7 +409,7 @@ public class WifiAwareManager { /** @hide */ public void publish(int clientId, Looper looper, PublishConfig publishConfig, - WifiAwareDiscoverySessionCallback callback) { + DiscoverySessionCallback callback) { if (VDBG) Log.v(TAG, "publish(): clientId=" + clientId + ", config=" + publishConfig); try { @@ -437,7 +437,7 @@ public class WifiAwareManager { /** @hide */ public void subscribe(int clientId, Looper looper, SubscribeConfig subscribeConfig, - WifiAwareDiscoverySessionCallback callback) { + DiscoverySessionCallback callback) { if (VDBG) { if (VDBG) { Log.v(TAG, @@ -672,14 +672,14 @@ public class WifiAwareManager { } /** - * Constructs a {@link WifiAwareAttachCallback} using the specified looper. + * Constructs a {@link AttachCallback} using the specified looper. * All callbacks will delivered on the thread of the specified looper. * * @param looper The looper on which to execute the callbacks. */ WifiAwareEventCallbackProxy(WifiAwareManager mgr, Looper looper, Binder binder, - final WifiAwareAttachCallback attachCallback, - final WifiAwareIdentityChangedListener identityChangedListener) { + final AttachCallback attachCallback, + final IdentityChangedListener identityChangedListener) { mAwareManager = new WeakReference<>(mgr); mLooper = looper; mBinder = binder; @@ -828,14 +828,14 @@ public class WifiAwareManager { private final WeakReference mAwareManager; private final boolean mIsPublish; - private final WifiAwareDiscoverySessionCallback mOriginalCallback; + private final DiscoverySessionCallback mOriginalCallback; private final int mClientId; private final Handler mHandler; - private WifiAwareDiscoveryBaseSession mSession; + private DiscoverySession mSession; WifiAwareDiscoverySessionCallbackProxy(WifiAwareManager mgr, Looper looper, - boolean isPublish, WifiAwareDiscoverySessionCallback originalCallback, + boolean isPublish, DiscoverySessionCallback originalCallback, int clientId) { mAwareManager = new WeakReference<>(mgr); mIsPublish = isPublish; @@ -1006,13 +1006,13 @@ public class WifiAwareManager { } if (mIsPublish) { - WifiAwarePublishDiscoverySession session = new WifiAwarePublishDiscoverySession(mgr, + PublishDiscoverySession session = new PublishDiscoverySession(mgr, mClientId, sessionId); mSession = session; mOriginalCallback.onPublishStarted(session); } else { - WifiAwareSubscribeDiscoverySession - session = new WifiAwareSubscribeDiscoverySession(mgr, mClientId, sessionId); + SubscribeDiscoverySession + session = new SubscribeDiscoverySession(mgr, mClientId, sessionId); mSession = session; mOriginalCallback.onSubscribeStarted(session); } @@ -1030,15 +1030,4 @@ public class WifiAwareManager { mOriginalCallback.onSessionTerminated(reason); } } - - /** @hide PROPOSED_AWARE_API */ - public static class PeerHandle { - /** @hide */ - public PeerHandle(int peerId) { - this.peerId = peerId; - } - - /** @hide */ - public int peerId; - } } diff --git a/wifi/java/android/net/wifi/aware/WifiAwarePublishDiscoverySession.java b/wifi/java/android/net/wifi/aware/WifiAwarePublishDiscoverySession.java deleted file mode 100644 index 68786d17d38d..000000000000 --- a/wifi/java/android/net/wifi/aware/WifiAwarePublishDiscoverySession.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.aware; - -import android.annotation.NonNull; -import android.util.Log; - -/** - * A class representing a Aware publish session. Created when - * {@link WifiAwareSession#publish(PublishConfig, WifiAwareDiscoverySessionCallback, - * android.os.Handler)} is called and a discovery session is created and returned in - * {@link WifiAwareDiscoverySessionCallback#onPublishStarted(WifiAwarePublishDiscoverySession)}. See - * baseline functionality of all discovery sessions in {@link WifiAwareDiscoveryBaseSession}. This - * object allows updating an existing/running publish discovery session using - * {@link #updatePublish(PublishConfig)}. - * - * @hide PROPOSED_AWARE_API - */ -public class WifiAwarePublishDiscoverySession extends WifiAwareDiscoveryBaseSession { - private static final String TAG = "WifiAwarePublishDiscSsn"; - - /** @hide */ - public WifiAwarePublishDiscoverySession(WifiAwareManager manager, int clientId, int sessionId) { - super(manager, clientId, sessionId); - } - - /** - * Re-configure the currently active publish session. The - * {@link WifiAwareDiscoverySessionCallback} is not replaced - the same listener used - * at creation is still used. The results of the configuration are returned using - * {@link WifiAwareDiscoverySessionCallback}: - *
      - *
    • {@link WifiAwareDiscoverySessionCallback#onSessionConfigUpdated()}: configuration - * update succeeded. - *
    • {@link WifiAwareDiscoverySessionCallback#onSessionConfigFailed()}: configuration - * update failed. The publish discovery session is still running using its previous - * configuration (i.e. update failure does not terminate the session). - *
    - * - * @param publishConfig The new discovery publish session configuration ({@link PublishConfig}). - */ - public void updatePublish(@NonNull PublishConfig publishConfig) { - if (mTerminated) { - Log.w(TAG, "updatePublish: called on terminated session"); - return; - } else { - WifiAwareManager mgr = mMgr.get(); - if (mgr == null) { - Log.w(TAG, "updatePublish: called post GC on WifiAwareManager"); - return; - } - - mgr.updatePublish(mClientId, mSessionId, publishConfig); - } - } -} diff --git a/wifi/java/android/net/wifi/aware/WifiAwareSession.java b/wifi/java/android/net/wifi/aware/WifiAwareSession.java index 005895a28043..e3ebe860f55f 100644 --- a/wifi/java/android/net/wifi/aware/WifiAwareSession.java +++ b/wifi/java/android/net/wifi/aware/WifiAwareSession.java @@ -65,7 +65,7 @@ public class WifiAwareSession { * session-wide destroy. *

    * An application may re-attach after a destroy using - * {@link WifiAwareManager#attach(WifiAwareAttachCallback, Handler)} . + * {@link WifiAwareManager#attach(AttachCallback, Handler)} . */ public void destroy() { WifiAwareManager mgr = mMgr.get(); @@ -95,22 +95,22 @@ public class WifiAwareSession { /** * Issue a request to the Aware service to create a new Aware publish discovery session, using * the specified {@code publishConfig} configuration. The results of the publish operation - * are routed to the callbacks of {@link WifiAwareDiscoverySessionCallback}: + * are routed to the callbacks of {@link DiscoverySessionCallback}: *

      *
    • - * {@link WifiAwareDiscoverySessionCallback#onPublishStarted( - * WifiAwarePublishDiscoverySession)} + * {@link DiscoverySessionCallback#onPublishStarted( + *PublishDiscoverySession)} * 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. - *
    • {@link WifiAwareDiscoverySessionCallback#onSessionConfigFailed()} is called if the + *
    • {@link DiscoverySessionCallback#onSessionConfigFailed()} is called if the * publish operation failed. *
    *

    * Other results of the publish session operations will also be routed to callbacks * on the {@code callback} object. The resulting publish session can be modified using - * {@link WifiAwarePublishDiscoverySession#updatePublish(PublishConfig)}. + * {@link PublishDiscoverySession#updatePublish(PublishConfig)}. *

    - * An application must use the {@link WifiAwareDiscoveryBaseSession#destroy()} to + * An application must use the {@link DiscoverySession#destroy()} to * terminate the publish discovery session once it isn't needed. This will free * resources as well terminate any on-air transmissions. *

    The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} @@ -118,13 +118,13 @@ public class WifiAwareSession { * * @param publishConfig The {@link PublishConfig} specifying the * configuration of the requested publish session. - * @param callback A {@link WifiAwareDiscoverySessionCallback} derived object to be used for + * @param callback A {@link DiscoverySessionCallback} derived object to be used for * session event callbacks. * @param handler The Handler on whose thread to execute the callbacks of the {@code * callback} object. If a null is provided then the application's main thread will be used. */ public void publish(@NonNull PublishConfig publishConfig, - @NonNull WifiAwareDiscoverySessionCallback callback, @Nullable Handler handler) { + @NonNull DiscoverySessionCallback callback, @Nullable Handler handler) { WifiAwareManager mgr = mMgr.get(); if (mgr == null) { Log.e(TAG, "publish: called post GC on WifiAwareManager"); @@ -141,22 +141,22 @@ public class WifiAwareSession { /** * Issue a request to the Aware service to create a new Aware subscribe discovery session, using * the specified {@code subscribeConfig} configuration. The results of the subscribe - * operation are routed to the callbacks of {@link WifiAwareDiscoverySessionCallback}: + * operation are routed to the callbacks of {@link DiscoverySessionCallback}: *

      *
    • - * {@link WifiAwareDiscoverySessionCallback#onSubscribeStarted( - * WifiAwareSubscribeDiscoverySession)} + * {@link DiscoverySessionCallback#onSubscribeStarted( + *SubscribeDiscoverySession)} * 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. - *
    • {@link WifiAwareDiscoverySessionCallback#onSessionConfigFailed()} is called if the + *
    • {@link DiscoverySessionCallback#onSessionConfigFailed()} is called if the * subscribe operation failed. *
    *

    * Other results of the subscribe session operations will also be routed to callbacks * on the {@code callback} object. The resulting subscribe session can be modified using - * {@link WifiAwareSubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. + * {@link SubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}. *

    - * An application must use the {@link WifiAwareDiscoveryBaseSession#destroy()} to + * An application must use the {@link DiscoverySession#destroy()} to * terminate the subscribe discovery session once it isn't needed. This will free * resources as well terminate any on-air transmissions. *

    The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} @@ -164,13 +164,13 @@ public class WifiAwareSession { * * @param subscribeConfig The {@link SubscribeConfig} specifying the * configuration of the requested subscribe session. - * @param callback A {@link WifiAwareDiscoverySessionCallback} derived object to be used for + * @param callback A {@link DiscoverySessionCallback} derived object to be used for * session event callbacks. * @param handler The Handler on whose thread to execute the callbacks of the {@code * callback} object. If a null is provided then the application's main thread will be used. */ public void subscribe(@NonNull SubscribeConfig subscribeConfig, - @NonNull WifiAwareDiscoverySessionCallback callback, @Nullable Handler handler) { + @NonNull DiscoverySessionCallback callback, @Nullable Handler handler) { WifiAwareManager mgr = mMgr.get(); if (mgr == null) { Log.e(TAG, "publish: called post GC on WifiAwareManager"); @@ -193,7 +193,7 @@ public class WifiAwareSession { * This API is targeted for applications which can obtain the peer MAC address using OOB * (out-of-band) discovery. Aware discovery does not provide the MAC address of the peer - * when using Aware discovery use the alternative network specifier method - - * {@link WifiAwareDiscoveryBaseSession#createNetworkSpecifier(WifiAwareManager.PeerHandle, + * {@link DiscoverySession#createNetworkSpecifier(PeerHandle, * byte[])}. * * @param role The role of this device: diff --git a/wifi/java/android/net/wifi/aware/WifiAwareSubscribeDiscoverySession.java b/wifi/java/android/net/wifi/aware/WifiAwareSubscribeDiscoverySession.java deleted file mode 100644 index a0ec8093a3ab..000000000000 --- a/wifi/java/android/net/wifi/aware/WifiAwareSubscribeDiscoverySession.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.aware; - -import android.annotation.NonNull; -import android.util.Log; - -/** - * A class representing a Aware subscribe session. Created when - * {@link WifiAwareSession#subscribe(SubscribeConfig, - * WifiAwareDiscoverySessionCallback, android.os.Handler)} - * is called and a discovery session is created and returned in - * {@link WifiAwareDiscoverySessionCallback#onSubscribeStarted(WifiAwareSubscribeDiscoverySession)}. - * See baseline functionality of all discovery sessions in {@link WifiAwareDiscoveryBaseSession}. - * This object allows updating an existing/running subscribe discovery session using - * {@link #updateSubscribe(SubscribeConfig)}. - * - * @hide PROPOSED_AWARE_API - */ -public class WifiAwareSubscribeDiscoverySession extends WifiAwareDiscoveryBaseSession { - private static final String TAG = "WifiAwareSubsDiscSsn"; - - /** - * {@hide} - */ - public WifiAwareSubscribeDiscoverySession(WifiAwareManager manager, int clientId, - int sessionId) { - super(manager, clientId, sessionId); - } - - /** - * Re-configure the currently active subscribe session. The - * {@link WifiAwareDiscoverySessionCallback} is not replaced - the same listener used - * at creation is still used. The results of the configuration are returned using - * {@link WifiAwareDiscoverySessionCallback}: - *

      - *
    • {@link WifiAwareDiscoverySessionCallback#onSessionConfigUpdated()}: configuration - * update succeeded. - *
    • {@link WifiAwareDiscoverySessionCallback#onSessionConfigFailed()}: configuration - * update failed. The subscribe discovery session is still running using its previous - * configuration (i.e. update failure does not terminate the session). - *
    - * - * @param subscribeConfig The new discovery subscribe session configuration - * ({@link SubscribeConfig}). - */ - public void updateSubscribe(@NonNull SubscribeConfig subscribeConfig) { - if (mTerminated) { - Log.w(TAG, "updateSubscribe: called on terminated session"); - return; - } else { - WifiAwareManager mgr = mMgr.get(); - if (mgr == null) { - Log.w(TAG, "updateSubscribe: called post GC on WifiAwareManager"); - return; - } - - mgr.updateSubscribe(mClientId, mSessionId, subscribeConfig); - } - } -} diff --git a/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java b/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java index 24c0127cb11b..bcd7772b263d 100644 --- a/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java +++ b/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java @@ -67,19 +67,19 @@ public class WifiAwareManagerTest { public Context mockContext; @Mock - public WifiAwareAttachCallback mockCallback; + public AttachCallback mockCallback; @Mock - public WifiAwareDiscoverySessionCallback mockSessionCallback; + public DiscoverySessionCallback mockSessionCallback; @Mock public IWifiAwareManager mockAwareService; @Mock - public WifiAwarePublishDiscoverySession mockPublishSession; + public PublishDiscoverySession mockPublishSession; @Mock - public WifiAwareSubscribeDiscoverySession mockSubscribeSession; + public SubscribeDiscoverySession mockSubscribeSession; @Mock public RttManager.RttListener mockRttListener; @@ -276,7 +276,7 @@ public class WifiAwareManagerTest { final int sessionId = 123; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); final PublishConfig publishConfig = new PublishConfig.Builder().build(); - final WifiAwareManager.PeerHandle peerHandle = new WifiAwareManager.PeerHandle(873); + final PeerHandle peerHandle = new PeerHandle(873); final String string1 = "hey from here..."; final byte[] matchFilter = { 1, 12, 2, 31, 32 }; final int messageId = 2123; @@ -290,10 +290,9 @@ public class WifiAwareManagerTest { .forClass(IWifiAwareEventCallback.class); ArgumentCaptor sessionProxyCallback = ArgumentCaptor .forClass(IWifiAwareDiscoverySessionCallback.class); - ArgumentCaptor publishSession = ArgumentCaptor - .forClass(WifiAwarePublishDiscoverySession.class); - ArgumentCaptor peerIdCaptor = ArgumentCaptor.forClass( - WifiAwareManager.PeerHandle.class); + ArgumentCaptor publishSession = ArgumentCaptor + .forClass(PublishDiscoverySession.class); + ArgumentCaptor peerIdCaptor = ArgumentCaptor.forClass(PeerHandle.class); ArgumentCaptor> matchFilterCaptor = ArgumentCaptor.forClass( (Class) List.class); @@ -377,7 +376,7 @@ public class WifiAwareManagerTest { final int sessionId = 123; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); final PublishConfig publishConfig = new PublishConfig.Builder().build(); - final int reason = WifiAwareDiscoverySessionCallback.TERMINATE_REASON_DONE; + final int reason = DiscoverySessionCallback.TERMINATE_REASON_DONE; InOrder inOrder = inOrder(mockCallback, mockSessionCallback, mockAwareService, mockPublishSession); @@ -387,8 +386,8 @@ public class WifiAwareManagerTest { .forClass(IWifiAwareEventCallback.class); ArgumentCaptor sessionProxyCallback = ArgumentCaptor .forClass(IWifiAwareDiscoverySessionCallback.class); - ArgumentCaptor publishSession = ArgumentCaptor - .forClass(WifiAwarePublishDiscoverySession.class); + ArgumentCaptor publishSession = ArgumentCaptor + .forClass(PublishDiscoverySession.class); // (1) connect successfully mDut.attach(mMockLooperHandler, configRequest, mockCallback, null); @@ -428,7 +427,7 @@ public class WifiAwareManagerTest { final int sessionId = 123; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); final SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().build(); - final WifiAwareManager.PeerHandle peerHandle = new WifiAwareManager.PeerHandle(873); + final PeerHandle peerHandle = new PeerHandle(873); final String string1 = "hey from here..."; final byte[] matchFilter = { 1, 12, 3, 31, 32 }; // bad data! final int messageId = 2123; @@ -442,10 +441,9 @@ public class WifiAwareManagerTest { .forClass(IWifiAwareEventCallback.class); ArgumentCaptor sessionProxyCallback = ArgumentCaptor .forClass(IWifiAwareDiscoverySessionCallback.class); - ArgumentCaptor subscribeSession = ArgumentCaptor - .forClass(WifiAwareSubscribeDiscoverySession.class); - ArgumentCaptor peerIdCaptor = ArgumentCaptor.forClass( - WifiAwareManager.PeerHandle.class); + ArgumentCaptor subscribeSession = ArgumentCaptor + .forClass(SubscribeDiscoverySession.class); + ArgumentCaptor peerIdCaptor = ArgumentCaptor.forClass(PeerHandle.class); // (0) connect + success mDut.attach(mMockLooperHandler, configRequest, mockCallback, null); @@ -516,7 +514,7 @@ public class WifiAwareManagerTest { final int sessionId = 123; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); final SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().build(); - final int reason = WifiAwareDiscoverySessionCallback.TERMINATE_REASON_DONE; + final int reason = DiscoverySessionCallback.TERMINATE_REASON_DONE; InOrder inOrder = inOrder(mockCallback, mockSessionCallback, mockAwareService, mockSubscribeSession); @@ -526,8 +524,8 @@ public class WifiAwareManagerTest { .forClass(IWifiAwareEventCallback.class); ArgumentCaptor sessionProxyCallback = ArgumentCaptor .forClass(IWifiAwareDiscoverySessionCallback.class); - ArgumentCaptor subscribeSession = ArgumentCaptor - .forClass(WifiAwareSubscribeDiscoverySession.class); + ArgumentCaptor subscribeSession = ArgumentCaptor + .forClass(SubscribeDiscoverySession.class); // (1) connect successfully mDut.attach(mMockLooperHandler, configRequest, mockCallback, null); @@ -892,8 +890,8 @@ public class WifiAwareManagerTest { .forClass(IWifiAwareEventCallback.class); ArgumentCaptor sessionProxyCallback = ArgumentCaptor .forClass(IWifiAwareDiscoverySessionCallback.class); - ArgumentCaptor publishSession = ArgumentCaptor - .forClass(WifiAwarePublishDiscoverySession.class); + ArgumentCaptor publishSession = ArgumentCaptor + .forClass(PublishDiscoverySession.class); ArgumentCaptor rttParamCaptor = ArgumentCaptor .forClass(RttManager.ParcelableRttParams.class); ArgumentCaptor rttResultsCaptor = ArgumentCaptor @@ -953,7 +951,7 @@ public class WifiAwareManagerTest { public void testNetworkSpecifierWithClient() throws Exception { final int clientId = 4565; final int sessionId = 123; - final WifiAwareManager.PeerHandle peerHandle = new WifiAwareManager.PeerHandle(123412); + final PeerHandle peerHandle = new PeerHandle(123412); final int role = WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER; final String token = "Some arbitrary token string - can really be anything"; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -967,8 +965,8 @@ public class WifiAwareManagerTest { .forClass(IWifiAwareEventCallback.class); ArgumentCaptor sessionProxyCallback = ArgumentCaptor .forClass(IWifiAwareDiscoverySessionCallback.class); - ArgumentCaptor publishSession = ArgumentCaptor - .forClass(WifiAwarePublishDiscoverySession.class); + ArgumentCaptor publishSession = ArgumentCaptor + .forClass(PublishDiscoverySession.class); InOrder inOrder = inOrder(mockCallback, mockSessionCallback, mockAwareService, mockPublishSession, mockRttListener); -- cgit v1.2.3-59-g8ed1b