Merge "[NAN] Update API: replace looper with handler"
am: 0027ddf990
Change-Id: I6d3934255c9c6e8085830eeab527479b292bac07
This commit is contained in:
@@ -23,7 +23,7 @@ import android.os.Parcelable;
|
||||
/**
|
||||
* Defines a request object to configure a Wi-Fi NAN network. Built using
|
||||
* {@link ConfigRequest.Builder}. Configuration is requested using
|
||||
* {@link WifiNanManager#connect(android.os.Looper, ConfigRequest, WifiNanEventCallback)}.
|
||||
* {@link WifiNanManager#connect(android.os.Handler, ConfigRequest, WifiNanEventCallback)}.
|
||||
* Note that the actual achieved configuration may be different from the
|
||||
* requested configuration - since different applications may request different
|
||||
* configurations.
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Base class for NAN events callbacks. Should be extended by applications and set when calling
|
||||
* {@link WifiNanManager#connect(android.os.Looper, WifiNanEventCallback)}. These are callbacks
|
||||
* {@link WifiNanManager#connect(android.os.Handler, WifiNanEventCallback)}. These are callbacks
|
||||
* applying to the NAN connection as a whole - not to specific publish or subscribe sessions -
|
||||
* for that see {@link WifiNanSessionCallback}.
|
||||
*
|
||||
@@ -46,7 +46,7 @@ public class WifiNanEventCallback {
|
||||
|
||||
/**
|
||||
* Indicates that a {@link ConfigRequest} passed in
|
||||
* {@link WifiNanManager#connect(android.os.Looper, ConfigRequest, WifiNanEventCallback)}
|
||||
* {@link WifiNanManager#connect(android.os.Handler, ConfigRequest, WifiNanEventCallback)}
|
||||
* couldn't be applied since other connections already exist with an incompatible
|
||||
* configurations. Failure reason flag for {@link WifiNanEventCallback#onConnectFail(int)}.
|
||||
*/
|
||||
@@ -60,7 +60,7 @@ public class WifiNanEventCallback {
|
||||
|
||||
/**
|
||||
* Called when NAN connect operation
|
||||
* {@link WifiNanManager#connect(android.os.Looper, WifiNanEventCallback)}
|
||||
* {@link WifiNanManager#connect(android.os.Handler, WifiNanEventCallback)}
|
||||
* is completed and that we can now start discovery sessions or connections.
|
||||
*/
|
||||
public void onConnectSuccess() {
|
||||
@@ -69,7 +69,7 @@ public class WifiNanEventCallback {
|
||||
|
||||
/**
|
||||
* Called when NAN connect operation
|
||||
* {@link WifiNanManager#connect(android.os.Looper, WifiNanEventCallback)} failed.
|
||||
* {@link WifiNanManager#connect(android.os.Handler, WifiNanEventCallback)} failed.
|
||||
*
|
||||
* @param reason Failure reason code, see
|
||||
* {@code WifiNanEventCallback.REASON_*}.
|
||||
@@ -91,7 +91,7 @@ public class WifiNanEventCallback {
|
||||
* <p>
|
||||
* This callback is only called if the NAN connection enables it using
|
||||
* {@link ConfigRequest.Builder#setEnableIdentityChangeCallback(boolean)} in
|
||||
* {@link WifiNanManager#connect(android.os.Looper, ConfigRequest, WifiNanEventCallback)}
|
||||
* {@link WifiNanManager#connect(android.os.Handler, ConfigRequest, WifiNanEventCallback)}
|
||||
* . It is disabled by default since it may result in additional wake-ups of the host -
|
||||
* increasing power.
|
||||
*
|
||||
|
||||
@@ -60,7 +60,7 @@ import java.util.Arrays;
|
||||
* The class provides access to:
|
||||
* <ul>
|
||||
* <li>Initialize a NAN cluster (peer-to-peer synchronization). Refer to
|
||||
* {@link #connect(Looper, WifiNanEventCallback)}.
|
||||
* {@link #connect(Handler, WifiNanEventCallback)}.
|
||||
* <li>Create discovery sessions (publish or subscribe sessions).
|
||||
* Refer to {@link #publish(PublishConfig, WifiNanSessionCallback)} and
|
||||
* {@link #subscribe(SubscribeConfig, WifiNanSessionCallback)}.
|
||||
@@ -77,7 +77,7 @@ import java.util.Arrays;
|
||||
* Note that this broadcast is not sticky - you should register for it and then check the
|
||||
* above API to avoid a race condition.
|
||||
* <p>
|
||||
* An application must use {@link #connect(Looper, WifiNanEventCallback)} to initialize a NAN
|
||||
* An application must use {@link #connect(Handler, WifiNanEventCallback)} to initialize a NAN
|
||||
* cluster - before making any other NAN operation. NAN cluster membership is a device-wide
|
||||
* operation - the API guarantees that the device is in a cluster or joins a NAN cluster (or
|
||||
* starts one if none can be found). Information about connection success (or failure) are
|
||||
@@ -343,13 +343,13 @@ public class WifiNanManager {
|
||||
* Note: a NAN cluster is a shared resource - if the device is already connected to a cluster
|
||||
* than this function will simply indicate success immediately.
|
||||
*
|
||||
* @param looper The Looper on which to execute all callbacks related to the
|
||||
* @param handler The Handler on whose thread to execute all callbacks related to the
|
||||
* connection - including all sessions opened as part of this
|
||||
* connection.
|
||||
* connection. If a null is provided then the application's main thread will be used.
|
||||
* @param callback A callback extended from {@link WifiNanEventCallback}.
|
||||
*/
|
||||
public void connect(@NonNull Looper looper, @NonNull WifiNanEventCallback callback) {
|
||||
connect(looper, null, callback);
|
||||
public void connect(@Nullable Handler handler, @NonNull WifiNanEventCallback callback) {
|
||||
connect(handler, null, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -360,30 +360,31 @@ public class WifiNanManager {
|
||||
* An application <b>must</b> call {@link #disconnect()} when done with the Wi-Fi NAN
|
||||
* connection. Allows requesting a specific configuration using {@link ConfigRequest}. If not
|
||||
* necessary (default configuration should usually work) use the
|
||||
* {@link #connect(Looper, WifiNanEventCallback)} method instead.
|
||||
* {@link #connect(Handler, WifiNanEventCallback)} method instead.
|
||||
* <p>
|
||||
* Note: a NAN cluster is a shared resource - if the device is already connected to a cluster
|
||||
* than this function will simply indicate success immediately.
|
||||
*
|
||||
* @param looper The Looper on which to execute all callbacks related to the
|
||||
* @param handler The Handler on whose thread to execute all callbacks related to the
|
||||
* connection - including all sessions opened as part of this
|
||||
* connection.
|
||||
* connection. If a null is provided then the application's main thread will be used.
|
||||
* @param configRequest The requested NAN configuration.
|
||||
* @param callback A callback extended from {@link WifiNanEventCallback}.
|
||||
*/
|
||||
public void connect(@NonNull Looper looper, @Nullable ConfigRequest configRequest,
|
||||
public void connect(@Nullable Handler handler, @Nullable ConfigRequest configRequest,
|
||||
@NonNull WifiNanEventCallback callback) {
|
||||
if (VDBG) {
|
||||
Log.v(TAG, "connect(): looper=" + looper + ", callback=" + callback + ", configRequest="
|
||||
+ configRequest);
|
||||
Log.v(TAG,
|
||||
"connect(): handler=" + handler + ", callback=" + callback + ", configRequest="
|
||||
+ configRequest);
|
||||
}
|
||||
|
||||
synchronized (mLock) {
|
||||
mLooper = looper;
|
||||
mLooper = (handler == null) ? Looper.getMainLooper() : handler.getLooper();
|
||||
|
||||
try {
|
||||
mClientId = mService.connect(mBinder, mContext.getOpPackageName(),
|
||||
new WifiNanEventCallbackProxy(this, looper, callback), configRequest);
|
||||
new WifiNanEventCallbackProxy(this, mLooper, callback), configRequest);
|
||||
} catch (RemoteException e) {
|
||||
mClientId = INVALID_CLIENT_ID;
|
||||
mLooper = null;
|
||||
@@ -402,7 +403,7 @@ public class WifiNanManager {
|
||||
* connections explicitly before a disconnect.
|
||||
* <p>
|
||||
* An application may re-connect after a disconnect using
|
||||
* {@link WifiNanManager#connect(Looper, WifiNanEventCallback)} .
|
||||
* {@link WifiNanManager#connect(Handler, WifiNanEventCallback)} .
|
||||
*/
|
||||
public void disconnect() {
|
||||
if (VDBG) Log.v(TAG, "disconnect()");
|
||||
|
||||
Reference in New Issue
Block a user