Merge "[NAN] Update API: replace looper with handler"
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
|
* Defines a request object to configure a Wi-Fi NAN network. Built using
|
||||||
* {@link ConfigRequest.Builder}. Configuration is requested 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
|
* Note that the actual achieved configuration may be different from the
|
||||||
* requested configuration - since different applications may request different
|
* requested configuration - since different applications may request different
|
||||||
* configurations.
|
* 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
|
* 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 -
|
* applying to the NAN connection as a whole - not to specific publish or subscribe sessions -
|
||||||
* for that see {@link WifiNanSessionCallback}.
|
* for that see {@link WifiNanSessionCallback}.
|
||||||
*
|
*
|
||||||
@@ -46,7 +46,7 @@ public class WifiNanEventCallback {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that a {@link ConfigRequest} passed in
|
* 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
|
* couldn't be applied since other connections already exist with an incompatible
|
||||||
* configurations. Failure reason flag for {@link WifiNanEventCallback#onConnectFail(int)}.
|
* configurations. Failure reason flag for {@link WifiNanEventCallback#onConnectFail(int)}.
|
||||||
*/
|
*/
|
||||||
@@ -60,7 +60,7 @@ public class WifiNanEventCallback {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when NAN connect operation
|
* 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.
|
* is completed and that we can now start discovery sessions or connections.
|
||||||
*/
|
*/
|
||||||
public void onConnectSuccess() {
|
public void onConnectSuccess() {
|
||||||
@@ -69,7 +69,7 @@ public class WifiNanEventCallback {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when NAN connect operation
|
* 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
|
* @param reason Failure reason code, see
|
||||||
* {@code WifiNanEventCallback.REASON_*}.
|
* {@code WifiNanEventCallback.REASON_*}.
|
||||||
@@ -91,7 +91,7 @@ public class WifiNanEventCallback {
|
|||||||
* <p>
|
* <p>
|
||||||
* This callback is only called if the NAN connection enables it using
|
* This callback is only called if the NAN connection enables it using
|
||||||
* {@link ConfigRequest.Builder#setEnableIdentityChangeCallback(boolean)} in
|
* {@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 -
|
* . It is disabled by default since it may result in additional wake-ups of the host -
|
||||||
* increasing power.
|
* increasing power.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ import java.util.Arrays;
|
|||||||
* The class provides access to:
|
* The class provides access to:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Initialize a NAN cluster (peer-to-peer synchronization). Refer to
|
* <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).
|
* <li>Create discovery sessions (publish or subscribe sessions).
|
||||||
* Refer to {@link #publish(PublishConfig, WifiNanSessionCallback)} and
|
* Refer to {@link #publish(PublishConfig, WifiNanSessionCallback)} and
|
||||||
* {@link #subscribe(SubscribeConfig, WifiNanSessionCallback)}.
|
* {@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
|
* Note that this broadcast is not sticky - you should register for it and then check the
|
||||||
* above API to avoid a race condition.
|
* above API to avoid a race condition.
|
||||||
* <p>
|
* <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
|
* 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
|
* 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
|
* 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
|
* 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.
|
* 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 - 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}.
|
* @param callback A callback extended from {@link WifiNanEventCallback}.
|
||||||
*/
|
*/
|
||||||
public void connect(@NonNull Looper looper, @NonNull WifiNanEventCallback callback) {
|
public void connect(@Nullable Handler handler, @NonNull WifiNanEventCallback callback) {
|
||||||
connect(looper, null, 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
|
* 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
|
* connection. Allows requesting a specific configuration using {@link ConfigRequest}. If not
|
||||||
* necessary (default configuration should usually work) use the
|
* necessary (default configuration should usually work) use the
|
||||||
* {@link #connect(Looper, WifiNanEventCallback)} method instead.
|
* {@link #connect(Handler, WifiNanEventCallback)} method instead.
|
||||||
* <p>
|
* <p>
|
||||||
* Note: a NAN cluster is a shared resource - if the device is already connected to a cluster
|
* 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.
|
* 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 - 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 configRequest The requested NAN configuration.
|
||||||
* @param callback A callback extended from {@link WifiNanEventCallback}.
|
* @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) {
|
@NonNull WifiNanEventCallback callback) {
|
||||||
if (VDBG) {
|
if (VDBG) {
|
||||||
Log.v(TAG, "connect(): looper=" + looper + ", callback=" + callback + ", configRequest="
|
Log.v(TAG,
|
||||||
+ configRequest);
|
"connect(): handler=" + handler + ", callback=" + callback + ", configRequest="
|
||||||
|
+ configRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mLooper = looper;
|
mLooper = (handler == null) ? Looper.getMainLooper() : handler.getLooper();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mClientId = mService.connect(mBinder, mContext.getOpPackageName(),
|
mClientId = mService.connect(mBinder, mContext.getOpPackageName(),
|
||||||
new WifiNanEventCallbackProxy(this, looper, callback), configRequest);
|
new WifiNanEventCallbackProxy(this, mLooper, callback), configRequest);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
mClientId = INVALID_CLIENT_ID;
|
mClientId = INVALID_CLIENT_ID;
|
||||||
mLooper = null;
|
mLooper = null;
|
||||||
@@ -402,7 +403,7 @@ public class WifiNanManager {
|
|||||||
* connections explicitly before a disconnect.
|
* connections explicitly before a disconnect.
|
||||||
* <p>
|
* <p>
|
||||||
* An application may re-connect after a disconnect using
|
* An application may re-connect after a disconnect using
|
||||||
* {@link WifiNanManager#connect(Looper, WifiNanEventCallback)} .
|
* {@link WifiNanManager#connect(Handler, WifiNanEventCallback)} .
|
||||||
*/
|
*/
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
if (VDBG) Log.v(TAG, "disconnect()");
|
if (VDBG) Log.v(TAG, "disconnect()");
|
||||||
|
|||||||
Reference in New Issue
Block a user