diff options
| author | 2017-04-20 15:13:24 -0700 | |
|---|---|---|
| committer | 2017-04-21 14:05:58 -0700 | |
| commit | a1d90d9e9fbe62561d3a77b2733b5fce3b92d17a (patch) | |
| tree | c92b4bd4d83f2df6b84fc7802eb044cb93f8b3b1 | |
| parent | fd25662e034e260e32616b680e25287b53a11452 (diff) | |
[AWARE] Add AutoCloseable interface/implementation
Make resource holding classes AutoCloseable. These are objects
which (already) require the client to call a destroy() method.
Note: the destroy() method was renamed to close() - no sense in
identical/duplicate methods.
Bug: 37514387
Test: unit tests and integration (sl4a) tests passing.
Merged-In: Ia14065ab9dcd92481412532bfdb198f2e8d9f83c
Change-Id: Ia14065ab9dcd92481412532bfdb198f2e8d9f83c
| -rw-r--r-- | api/current.txt | 8 | ||||
| -rw-r--r-- | api/system-current.txt | 8 | ||||
| -rw-r--r-- | api/test-current.txt | 8 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/aware/DiscoverySession.java | 9 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java | 2 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/aware/PublishConfig.java | 2 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/aware/SubscribeConfig.java | 2 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/aware/WifiAwareManager.java | 8 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/aware/WifiAwareSession.java | 10 | ||||
| -rw-r--r-- | wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java | 6 |
10 files changed, 32 insertions, 31 deletions
diff --git a/api/current.txt b/api/current.txt index 8cbb9ce9e942..3a09f9f24ca2 100644 --- a/api/current.txt +++ b/api/current.txt @@ -26737,10 +26737,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); } diff --git a/api/system-current.txt b/api/system-current.txt index 58b75374d7a7..7c0288c6eb32 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -29480,11 +29480,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[]); } @@ -29568,11 +29568,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); } diff --git a/api/test-current.txt b/api/test-current.txt index 2e401b4cb3a4..a6fce701ce7a 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -26844,10 +26844,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[]); } @@ -26931,10 +26931,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); } diff --git a/wifi/java/android/net/wifi/aware/DiscoverySession.java b/wifi/java/android/net/wifi/aware/DiscoverySession.java index bf5c42b8ca1c..c7e1fc739046 100644 --- a/wifi/java/android/net/wifi/aware/DiscoverySession.java +++ b/wifi/java/android/net/wifi/aware/DiscoverySession.java @@ -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(); diff --git a/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java b/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java index 334205b13bba..d8667e6cfcb6 100644 --- a/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java +++ b/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java @@ -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)}). */ diff --git a/wifi/java/android/net/wifi/aware/PublishConfig.java b/wifi/java/android/net/wifi/aware/PublishConfig.java index 1ce12f30a25e..0f1e99295bc1 100644 --- a/wifi/java/android/net/wifi/aware/PublishConfig.java +++ b/wifi/java/android/net/wifi/aware/PublishConfig.java @@ -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. diff --git a/wifi/java/android/net/wifi/aware/SubscribeConfig.java b/wifi/java/android/net/wifi/aware/SubscribeConfig.java index 97a6a3f91e86..3f11677bcc7f 100644 --- a/wifi/java/android/net/wifi/aware/SubscribeConfig.java +++ b/wifi/java/android/net/wifi/aware/SubscribeConfig.java @@ -346,7 +346,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. diff --git a/wifi/java/android/net/wifi/aware/WifiAwareManager.java b/wifi/java/android/net/wifi/aware/WifiAwareManager.java index 3fcbd4b60259..d3ed79245426 100644 --- a/wifi/java/android/net/wifi/aware/WifiAwareManager.java +++ b/wifi/java/android/net/wifi/aware/WifiAwareManager.java @@ -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 diff --git a/wifi/java/android/net/wifi/aware/WifiAwareSession.java b/wifi/java/android/net/wifi/aware/WifiAwareSession.java index ac3a6bba052c..4e060d5ca3f0 100644 --- a/wifi/java/android/net/wifi/aware/WifiAwareSession.java +++ b/wifi/java/android/net/wifi/aware/WifiAwareSession.java @@ -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} diff --git a/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java b/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java index 72a6a7a7b46b..423543fa25e3 100644 --- a/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java +++ b/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java @@ -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); |