Merge "[AWARE] Add AutoCloseable interface/implementation" into oc-dev

This commit is contained in:
Etan Cohen
2017-04-25 03:26:01 +00:00
committed by Android (Google) Code Review
10 changed files with 32 additions and 31 deletions

View File

@@ -26740,10 +26740,10 @@ package android.net.wifi.aware {
field public static final android.os.Parcelable.Creator<android.net.wifi.aware.Characteristics> CREATOR;
}
public class DiscoverySession {
public class DiscoverySession implements java.lang.AutoCloseable {
method public void close();
method public android.net.NetworkSpecifier createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle);
method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
method public void destroy();
method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
}
@@ -26824,10 +26824,10 @@ package android.net.wifi.aware {
field public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1; // 0x1
}
public class WifiAwareSession {
public class WifiAwareSession implements java.lang.AutoCloseable {
method public void close();
method public android.net.NetworkSpecifier createNetworkSpecifierOpen(int, byte[]);
method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
method public void destroy();
method public void publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
}

View File

@@ -29484,11 +29484,11 @@ package android.net.wifi.aware {
field public static final android.os.Parcelable.Creator<android.net.wifi.aware.Characteristics> CREATOR;
}
public class DiscoverySession {
public class DiscoverySession implements java.lang.AutoCloseable {
method public void close();
method public android.net.NetworkSpecifier createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle);
method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
method public android.net.NetworkSpecifier createNetworkSpecifierPmk(android.net.wifi.aware.PeerHandle, byte[]);
method public void destroy();
method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
}
@@ -29569,11 +29569,11 @@ package android.net.wifi.aware {
field public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1; // 0x1
}
public class WifiAwareSession {
public class WifiAwareSession implements java.lang.AutoCloseable {
method public void close();
method public android.net.NetworkSpecifier createNetworkSpecifierOpen(int, byte[]);
method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
method public android.net.NetworkSpecifier createNetworkSpecifierPmk(int, byte[], byte[]);
method public void destroy();
method public void publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
}

View File

@@ -26848,10 +26848,10 @@ package android.net.wifi.aware {
field public static final android.os.Parcelable.Creator<android.net.wifi.aware.Characteristics> CREATOR;
}
public class DiscoverySession {
public class DiscoverySession implements java.lang.AutoCloseable {
method public void close();
method public android.net.NetworkSpecifier createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle);
method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
method public void destroy();
method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
}
@@ -26932,10 +26932,10 @@ package android.net.wifi.aware {
field public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1; // 0x1
}
public class WifiAwareSession {
public class WifiAwareSession implements java.lang.AutoCloseable {
method public void close();
method public android.net.NetworkSpecifier createNetworkSpecifierOpen(int, byte[]);
method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
method public void destroy();
method public void publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
}

View File

@@ -38,10 +38,10 @@ import java.lang.ref.WeakReference;
* {@link #createNetworkSpecifierOpen(PeerHandle)} or
* {@link #createNetworkSpecifierPassphrase(PeerHandle, String)}.
* </ul>
* The {@link #destroy()} method must be called to destroy discovery sessions once they are
* The {@link #close()} method must be called to destroy discovery sessions once they are
* no longer needed.
*/
public class DiscoverySession {
public class DiscoverySession implements AutoCloseable {
private static final String TAG = "DiscoverySession";
private static final boolean DBG = false;
private static final boolean VDBG = false; // STOPSHIP if true
@@ -96,7 +96,8 @@ public class DiscoverySession {
* exception is a session for which we received a termination callback,
* {@link DiscoverySessionCallback#onSessionTerminated()}.
*/
public void destroy() {
@Override
public void close() {
WifiAwareManager mgr = mMgr.get();
if (mgr == null) {
Log.w(TAG, "destroy: called post GC on WifiAwareManager");
@@ -131,7 +132,7 @@ public class DiscoverySession {
try {
if (!mTerminated) {
mCloseGuard.warnIfOpen();
destroy();
close();
}
} finally {
super.finalize();

View File

@@ -84,7 +84,7 @@ public class DiscoverySessionCallback {
/**
* Called when a discovery session (publish or subscribe) terminates. Termination may be due
* to user-request (either directly through {@link DiscoverySession#destroy()} or
* to user-request (either directly through {@link DiscoverySession#close()} or
* application-specified expiration, e.g. {@link PublishConfig.Builder#setTtlSec(int)}
* or {@link SubscribeConfig.Builder#setTtlSec(int)}).
*/

View File

@@ -314,7 +314,7 @@ public final class PublishConfig implements Parcelable {
* {@link #setTerminateNotificationEnabled(boolean)} disables the callback].
* <p>
* Optional. 0 by default - indicating the session doesn't terminate on its own.
* Session will be terminated when {@link DiscoverySession#destroy()} is
* Session will be terminated when {@link DiscoverySession#close()} is
* called.
*
* @param ttlSec Lifetime of a publish session in seconds.

View File

@@ -313,7 +313,7 @@ public final class SubscribeConfig implements Parcelable {
* {@link DiscoverySessionCallback#onSessionTerminated()}.
* <p>
* Optional. 0 by default - indicating the session doesn't terminate on its own.
* Session will be terminated when {@link DiscoverySession#destroy()} is
* Session will be terminated when {@link DiscoverySession#close()} is
* called.
*
* @param ttlSec Lifetime of a subscribe session in seconds.

View File

@@ -82,7 +82,7 @@ import java.util.List;
* discovery or connection setup only after receiving confirmation that Aware attach
* succeeded - {@link AttachCallback#onAttached(WifiAwareSession)}. When an
* application is finished using Aware it <b>must</b> use the
* {@link WifiAwareSession#destroy()} API to indicate to the Aware service that the device
* {@link WifiAwareSession#close()} 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.
* <p>
@@ -104,7 +104,7 @@ import java.util.List;
* also be used to send messages using the
* {@link DiscoverySession#sendMessage(PeerHandle, int, byte[])} APIs. When an
* application is finished with a discovery session it <b>must</b> terminate it using the
* {@link DiscoverySession#destroy()} API.
* {@link DiscoverySession#close()} API.
* <p>
* Creating connections between Aware devices is managed by the standard
* {@link ConnectivityManager#requestNetwork(NetworkRequest,
@@ -215,7 +215,7 @@ public class WifiAwareManager {
* create connections to peers. The device will attach to an existing cluster if it can find
* one or create a new cluster (if it is the first to enable Aware in its vicinity). Results
* (e.g. successful attach to a cluster) are provided to the {@code attachCallback} object.
* An application <b>must</b> call {@link WifiAwareSession#destroy()} when done with the
* An application <b>must</b> call {@link WifiAwareSession#close()} when done with the
* Wi-Fi Aware object.
* <p>
* Note: a Aware cluster is a shared resource - if the device is already attached to a cluster
@@ -237,7 +237,7 @@ public class WifiAwareManager {
* create connections to peers. The device will attach to an existing cluster if it can find
* one or create a new cluster (if it is the first to enable Aware in its vicinity). Results
* (e.g. successful attach to a cluster) are provided to the {@code attachCallback} object.
* An application <b>must</b> call {@link WifiAwareSession#destroy()} when done with the
* An application <b>must</b> call {@link WifiAwareSession#close()} when done with the
* Wi-Fi Aware object.
* <p>
* Note: a Aware cluster is a shared resource - if the device is already attached to a cluster

View File

@@ -33,7 +33,7 @@ import java.lang.ref.WeakReference;
* This class represents a Wi-Fi Aware session - an attachment to the Wi-Fi Aware service through
* which the app can execute discovery operations.
*/
public class WifiAwareSession {
public class WifiAwareSession implements AutoCloseable {
private static final String TAG = "WifiAwareSession";
private static final boolean DBG = false;
private static final boolean VDBG = false; // STOPSHIP if true
@@ -67,7 +67,7 @@ public class WifiAwareSession {
* An application may re-attach after a destroy using
* {@link WifiAwareManager#attach(AttachCallback, Handler)} .
*/
public void destroy() {
public void close() {
WifiAwareManager mgr = mMgr.get();
if (mgr == null) {
Log.w(TAG, "destroy: called post GC on WifiAwareManager");
@@ -85,7 +85,7 @@ public class WifiAwareSession {
try {
if (!mTerminated) {
mCloseGuard.warnIfOpen();
destroy();
close();
}
} finally {
super.finalize();
@@ -110,7 +110,7 @@ public class WifiAwareSession {
* on the {@code callback} object. The resulting publish session can be modified using
* {@link PublishDiscoverySession#updatePublish(PublishConfig)}.
* <p>
* An application must use the {@link DiscoverySession#destroy()} to
* An application must use the {@link DiscoverySession#close()} to
* terminate the publish discovery session once it isn't needed. This will free
* resources as well terminate any on-air transmissions.
* <p>The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
@@ -156,7 +156,7 @@ public class WifiAwareSession {
* on the {@code callback} object. The resulting subscribe session can be modified using
* {@link SubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}.
* <p>
* An application must use the {@link DiscoverySession#destroy()} to
* An application must use the {@link DiscoverySession#close()} to
* terminate the subscribe discovery session once it isn't needed. This will free
* resources as well terminate any on-air transmissions.
* <p>The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}

View File

@@ -150,7 +150,7 @@ public class WifiAwareManagerTest {
inOrder.verify(mockAwareService).publish(eq(clientId), eq(publishConfig), any());
// (3) disconnect
session.destroy();
session.close();
inOrder.verify(mockAwareService).disconnect(eq(clientId), eq(binder.getValue()));
// (4) try publishing again - fails silently
@@ -329,7 +329,7 @@ public class WifiAwareManagerTest {
inOrder.verify(mockSessionCallback).onSessionConfigFailed();
// (5) terminate
publishSession.getValue().destroy();
publishSession.getValue().close();
mMockLooper.dispatchAll();
inOrder.verify(mockAwareService).terminateSession(clientId, sessionId);
@@ -466,7 +466,7 @@ public class WifiAwareManagerTest {
inOrder.verify(mockSessionCallback).onSessionConfigFailed();
// (5) terminate
subscribeSession.getValue().destroy();
subscribeSession.getValue().close();
mMockLooper.dispatchAll();
inOrder.verify(mockAwareService).terminateSession(clientId, sessionId);