Merge "[AWARE] Add AutoCloseable interface/implementation" into oc-dev
This commit is contained in:
@@ -26740,10 +26740,10 @@ package android.net.wifi.aware {
|
|||||||
field public static final android.os.Parcelable.Creator<android.net.wifi.aware.Characteristics> CREATOR;
|
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 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 createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
|
||||||
method public void destroy();
|
|
||||||
method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
|
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
|
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 createNetworkSpecifierOpen(int, byte[]);
|
||||||
method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
|
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 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);
|
method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29484,11 +29484,11 @@ package android.net.wifi.aware {
|
|||||||
field public static final android.os.Parcelable.Creator<android.net.wifi.aware.Characteristics> CREATOR;
|
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 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 createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
|
||||||
method public android.net.NetworkSpecifier createNetworkSpecifierPmk(android.net.wifi.aware.PeerHandle, byte[]);
|
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[]);
|
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
|
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 createNetworkSpecifierOpen(int, byte[]);
|
||||||
method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
|
method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
|
||||||
method public android.net.NetworkSpecifier createNetworkSpecifierPmk(int, byte[], byte[]);
|
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 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);
|
method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26848,10 +26848,10 @@ package android.net.wifi.aware {
|
|||||||
field public static final android.os.Parcelable.Creator<android.net.wifi.aware.Characteristics> CREATOR;
|
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 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 createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle, java.lang.String);
|
||||||
method public void destroy();
|
|
||||||
method public void sendMessage(android.net.wifi.aware.PeerHandle, int, byte[]);
|
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
|
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 createNetworkSpecifierOpen(int, byte[]);
|
||||||
method public android.net.NetworkSpecifier createNetworkSpecifierPassphrase(int, byte[], java.lang.String);
|
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 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);
|
method public void subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ import java.lang.ref.WeakReference;
|
|||||||
* {@link #createNetworkSpecifierOpen(PeerHandle)} or
|
* {@link #createNetworkSpecifierOpen(PeerHandle)} or
|
||||||
* {@link #createNetworkSpecifierPassphrase(PeerHandle, String)}.
|
* {@link #createNetworkSpecifierPassphrase(PeerHandle, String)}.
|
||||||
* </ul>
|
* </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.
|
* no longer needed.
|
||||||
*/
|
*/
|
||||||
public class DiscoverySession {
|
public class DiscoverySession implements AutoCloseable {
|
||||||
private static final String TAG = "DiscoverySession";
|
private static final String TAG = "DiscoverySession";
|
||||||
private static final boolean DBG = false;
|
private static final boolean DBG = false;
|
||||||
private static final boolean VDBG = false; // STOPSHIP if true
|
private static final boolean VDBG = false; // STOPSHIP if true
|
||||||
@@ -96,7 +96,8 @@ public class DiscoverySession {
|
|||||||
* exception is a session for which we received a termination callback,
|
* exception is a session for which we received a termination callback,
|
||||||
* {@link DiscoverySessionCallback#onSessionTerminated()}.
|
* {@link DiscoverySessionCallback#onSessionTerminated()}.
|
||||||
*/
|
*/
|
||||||
public void destroy() {
|
@Override
|
||||||
|
public void close() {
|
||||||
WifiAwareManager mgr = mMgr.get();
|
WifiAwareManager mgr = mMgr.get();
|
||||||
if (mgr == null) {
|
if (mgr == null) {
|
||||||
Log.w(TAG, "destroy: called post GC on WifiAwareManager");
|
Log.w(TAG, "destroy: called post GC on WifiAwareManager");
|
||||||
@@ -131,7 +132,7 @@ public class DiscoverySession {
|
|||||||
try {
|
try {
|
||||||
if (!mTerminated) {
|
if (!mTerminated) {
|
||||||
mCloseGuard.warnIfOpen();
|
mCloseGuard.warnIfOpen();
|
||||||
destroy();
|
close();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
super.finalize();
|
super.finalize();
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class DiscoverySessionCallback {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a discovery session (publish or subscribe) terminates. Termination may be due
|
* 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)}
|
* application-specified expiration, e.g. {@link PublishConfig.Builder#setTtlSec(int)}
|
||||||
* or {@link SubscribeConfig.Builder#setTtlSec(int)}).
|
* or {@link SubscribeConfig.Builder#setTtlSec(int)}).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ public final class PublishConfig implements Parcelable {
|
|||||||
* {@link #setTerminateNotificationEnabled(boolean)} disables the callback].
|
* {@link #setTerminateNotificationEnabled(boolean)} disables the callback].
|
||||||
* <p>
|
* <p>
|
||||||
* Optional. 0 by default - indicating the session doesn't terminate on its own.
|
* 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.
|
* called.
|
||||||
*
|
*
|
||||||
* @param ttlSec Lifetime of a publish session in seconds.
|
* @param ttlSec Lifetime of a publish session in seconds.
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ public final class SubscribeConfig implements Parcelable {
|
|||||||
* {@link DiscoverySessionCallback#onSessionTerminated()}.
|
* {@link DiscoverySessionCallback#onSessionTerminated()}.
|
||||||
* <p>
|
* <p>
|
||||||
* Optional. 0 by default - indicating the session doesn't terminate on its own.
|
* 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.
|
* called.
|
||||||
*
|
*
|
||||||
* @param ttlSec Lifetime of a subscribe session in seconds.
|
* @param ttlSec Lifetime of a subscribe session in seconds.
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ import java.util.List;
|
|||||||
* discovery or connection setup only after receiving confirmation that Aware attach
|
* discovery or connection setup only after receiving confirmation that Aware attach
|
||||||
* succeeded - {@link AttachCallback#onAttached(WifiAwareSession)}. When an
|
* succeeded - {@link AttachCallback#onAttached(WifiAwareSession)}. When an
|
||||||
* application is finished using Aware it <b>must</b> use the
|
* 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
|
* may detach from the Aware cluster. The device will actually disable Aware once the last
|
||||||
* application detaches.
|
* application detaches.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -104,7 +104,7 @@ import java.util.List;
|
|||||||
* also be used to send messages using the
|
* also be used to send messages using the
|
||||||
* {@link DiscoverySession#sendMessage(PeerHandle, int, byte[])} APIs. When an
|
* {@link DiscoverySession#sendMessage(PeerHandle, int, byte[])} APIs. When an
|
||||||
* application is finished with a discovery session it <b>must</b> terminate it using the
|
* application is finished with a discovery session it <b>must</b> terminate it using the
|
||||||
* {@link DiscoverySession#destroy()} API.
|
* {@link DiscoverySession#close()} API.
|
||||||
* <p>
|
* <p>
|
||||||
* Creating connections between Aware devices is managed by the standard
|
* Creating connections between Aware devices is managed by the standard
|
||||||
* {@link ConnectivityManager#requestNetwork(NetworkRequest,
|
* {@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
|
* 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
|
* 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.
|
* (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.
|
* Wi-Fi Aware object.
|
||||||
* <p>
|
* <p>
|
||||||
* Note: a Aware cluster is a shared resource - if the device is already attached to a cluster
|
* 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
|
* 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
|
* 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.
|
* (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.
|
* Wi-Fi Aware object.
|
||||||
* <p>
|
* <p>
|
||||||
* Note: a Aware cluster is a shared resource - if the device is already attached to a cluster
|
* Note: a Aware cluster is a shared resource - if the device is already attached to a cluster
|
||||||
|
|||||||
@@ -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
|
* This class represents a Wi-Fi Aware session - an attachment to the Wi-Fi Aware service through
|
||||||
* which the app can execute discovery operations.
|
* which the app can execute discovery operations.
|
||||||
*/
|
*/
|
||||||
public class WifiAwareSession {
|
public class WifiAwareSession implements AutoCloseable {
|
||||||
private static final String TAG = "WifiAwareSession";
|
private static final String TAG = "WifiAwareSession";
|
||||||
private static final boolean DBG = false;
|
private static final boolean DBG = false;
|
||||||
private static final boolean VDBG = false; // STOPSHIP if true
|
private static final boolean VDBG = false; // STOPSHIP if true
|
||||||
@@ -67,7 +67,7 @@ public class WifiAwareSession {
|
|||||||
* An application may re-attach after a destroy using
|
* An application may re-attach after a destroy using
|
||||||
* {@link WifiAwareManager#attach(AttachCallback, Handler)} .
|
* {@link WifiAwareManager#attach(AttachCallback, Handler)} .
|
||||||
*/
|
*/
|
||||||
public void destroy() {
|
public void close() {
|
||||||
WifiAwareManager mgr = mMgr.get();
|
WifiAwareManager mgr = mMgr.get();
|
||||||
if (mgr == null) {
|
if (mgr == null) {
|
||||||
Log.w(TAG, "destroy: called post GC on WifiAwareManager");
|
Log.w(TAG, "destroy: called post GC on WifiAwareManager");
|
||||||
@@ -85,7 +85,7 @@ public class WifiAwareSession {
|
|||||||
try {
|
try {
|
||||||
if (!mTerminated) {
|
if (!mTerminated) {
|
||||||
mCloseGuard.warnIfOpen();
|
mCloseGuard.warnIfOpen();
|
||||||
destroy();
|
close();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
super.finalize();
|
super.finalize();
|
||||||
@@ -110,7 +110,7 @@ public class WifiAwareSession {
|
|||||||
* on the {@code callback} object. The resulting publish session can be modified using
|
* on the {@code callback} object. The resulting publish session can be modified using
|
||||||
* {@link PublishDiscoverySession#updatePublish(PublishConfig)}.
|
* {@link PublishDiscoverySession#updatePublish(PublishConfig)}.
|
||||||
* <p>
|
* <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
|
* terminate the publish discovery session once it isn't needed. This will free
|
||||||
* resources as well terminate any on-air transmissions.
|
* resources as well terminate any on-air transmissions.
|
||||||
* <p>The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
|
* <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
|
* on the {@code callback} object. The resulting subscribe session can be modified using
|
||||||
* {@link SubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}.
|
* {@link SubscribeDiscoverySession#updateSubscribe(SubscribeConfig)}.
|
||||||
* <p>
|
* <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
|
* terminate the subscribe discovery session once it isn't needed. This will free
|
||||||
* resources as well terminate any on-air transmissions.
|
* resources as well terminate any on-air transmissions.
|
||||||
* <p>The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
|
* <p>The application must have the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ public class WifiAwareManagerTest {
|
|||||||
inOrder.verify(mockAwareService).publish(eq(clientId), eq(publishConfig), any());
|
inOrder.verify(mockAwareService).publish(eq(clientId), eq(publishConfig), any());
|
||||||
|
|
||||||
// (3) disconnect
|
// (3) disconnect
|
||||||
session.destroy();
|
session.close();
|
||||||
inOrder.verify(mockAwareService).disconnect(eq(clientId), eq(binder.getValue()));
|
inOrder.verify(mockAwareService).disconnect(eq(clientId), eq(binder.getValue()));
|
||||||
|
|
||||||
// (4) try publishing again - fails silently
|
// (4) try publishing again - fails silently
|
||||||
@@ -329,7 +329,7 @@ public class WifiAwareManagerTest {
|
|||||||
inOrder.verify(mockSessionCallback).onSessionConfigFailed();
|
inOrder.verify(mockSessionCallback).onSessionConfigFailed();
|
||||||
|
|
||||||
// (5) terminate
|
// (5) terminate
|
||||||
publishSession.getValue().destroy();
|
publishSession.getValue().close();
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockAwareService).terminateSession(clientId, sessionId);
|
inOrder.verify(mockAwareService).terminateSession(clientId, sessionId);
|
||||||
|
|
||||||
@@ -466,7 +466,7 @@ public class WifiAwareManagerTest {
|
|||||||
inOrder.verify(mockSessionCallback).onSessionConfigFailed();
|
inOrder.verify(mockSessionCallback).onSessionConfigFailed();
|
||||||
|
|
||||||
// (5) terminate
|
// (5) terminate
|
||||||
subscribeSession.getValue().destroy();
|
subscribeSession.getValue().close();
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockAwareService).terminateSession(clientId, sessionId);
|
inOrder.verify(mockAwareService).terminateSession(clientId, sessionId);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user