* <li>Initialize a NAN cluster (peer-to-peer synchronization). Refer to
* {@link #attach(Handler, WifiNanAttachCallback)}.
* <li>Create discovery sessions (publish or subscribe sessions). Refer to
- * {@link WifiNanSession#publish(PublishConfig, WifiNanDiscoverySessionCallback)} and
- * {@link WifiNanSession#subscribe(SubscribeConfig, WifiNanDiscoverySessionCallback)}.
+ * {@link WifiNanSession#publish(Handler, PublishConfig, WifiNanDiscoverySessionCallback)} and
+ * {@link WifiNanSession#subscribe(Handler, SubscribeConfig, WifiNanDiscoverySessionCallback)}.
* <li>Create a NAN network specifier to be used with
* {@link ConnectivityManager#requestNetwork(NetworkRequest, ConnectivityManager.NetworkCallback)}
* to set-up a NAN connection with a peer. Refer to
* device will actually disable NAN once the last application detaches.
* <p>
* Once a NAN attach is confirmed use the
- * {@link WifiNanSession#publish(PublishConfig, WifiNanDiscoverySessionCallback)} or
- * {@link WifiNanSession#subscribe(SubscribeConfig, WifiNanDiscoverySessionCallback)} to
+ * {@link WifiNanSession#publish(Handler, PublishConfig, WifiNanDiscoverySessionCallback)} or
+ * {@link WifiNanSession#subscribe(Handler, SubscribeConfig, WifiNanDiscoverySessionCallback)} to
* create publish or subscribe NAN discovery sessions. Events are called on the provided
* callback object {@link WifiNanDiscoverySessionCallback}. Specifically, the
* {@link WifiNanDiscoverySessionCallback#onPublishStarted(WifiNanPublishDiscoverySession)}
* then this function will simply indicate success immediately using the same {@code
* attachCallback}.
*
- * @param handler The Handler on whose thread to execute all callbacks related to the
- * attach request - including all sessions opened as part of this
- * attach. If a null is provided then the application's main thread will be used.
+ * @param handler The Handler on whose thread to execute the callbacks of the {@code
+ * attachCallback} object. If a null is provided then the application's main thread will be
+ * used.
* @param attachCallback A callback for attach events, extended from
* {@link WifiNanAttachCallback}.
*/
* requirements this listener will wake up the host at regular intervals causing higher power
* consumption, do not use it unless the information is necessary (e.g. for OOB discovery).
*
- * @param handler The Handler on whose thread to execute all callbacks related to the
- * attach request - including all sessions opened as part of this
- * attach. If a null is provided then the application's main thread will be used.
+ * @param handler The Handler on whose thread to execute the callbacks of the {@code
+ * attachCallback} and {@code identityChangedListener} objects. If a null is provided then the
+ * application's main thread will be used.
* @param attachCallback A callback for attach events, extended from
* {@link WifiNanAttachCallback}.
- * @param identityChangedListener A listener for changed identity.
+ * @param identityChangedListener A listener for changed identity, extended from
+ * {@link WifiNanIdentityChangedListener}.
*/
public void attach(@Nullable Handler handler, @NonNull WifiNanAttachCallback attachCallback,
@NonNull WifiNanIdentityChangedListener identityChangedListener) {
switch (msg.what) {
case CALLBACK_CONNECT_SUCCESS:
attachCallback.onAttached(
- new WifiNanSession(mgr, mBinder, mLooper, msg.arg1));
+ new WifiNanSession(mgr, mBinder, msg.arg1));
break;
case CALLBACK_CONNECT_FAIL:
mNanManager.clear();
private final WeakReference<WifiNanManager> mMgr;
private final Binder mBinder;
- private final Looper mLooper;
private final int mClientId;
private boolean mTerminated = true;
private final CloseGuard mCloseGuard = CloseGuard.get();
/** @hide */
- public WifiNanSession(WifiNanManager manager, Binder binder, Looper looper, int clientId) {
+ public WifiNanSession(WifiNanManager manager, Binder binder, int clientId) {
if (VDBG) Log.v(TAG, "New session created: manager=" + manager + ", clientId=" + clientId);
mMgr = new WeakReference<>(manager);
mBinder = binder;
- mLooper = looper;
mClientId = clientId;
mTerminated = false;
* session-wide destroy.
* <p>
* An application may re-attach after a destroy using
- * {@link WifiNanManager#attach(Handler, WifiNanEventCallback)} .
+ * {@link WifiNanManager#attach(Handler, WifiNanAttachCallback)} .
*/
public void destroy() {
WifiNanManager mgr = mMgr.get();
* terminate the publish discovery session once it isn't needed. This will free
* resources as well terminate any on-air transmissions.
*
+ * @param handler The Handler on whose thread to execute the callbacks of the {@code
+ * callback} object. If a null is provided then the application's main thread will be used.
* @param publishConfig The {@link PublishConfig} specifying the
* configuration of the requested publish session.
* @param callback A {@link WifiNanDiscoverySessionCallback} derived object to be used for
* session event callbacks.
*/
- public void publish(@NonNull PublishConfig publishConfig,
+ public void publish(@Nullable Handler handler, @NonNull PublishConfig publishConfig,
@NonNull WifiNanDiscoverySessionCallback callback) {
WifiNanManager mgr = mMgr.get();
if (mgr == null) {
Log.e(TAG, "publish: called after termination");
return;
}
- mgr.publish(mClientId, mLooper, publishConfig, callback);
+ mgr.publish(mClientId, (handler == null) ? Looper.getMainLooper() : handler.getLooper(),
+ publishConfig, callback);
}
/**
* terminate the subscribe discovery session once it isn't needed. This will free
* resources as well terminate any on-air transmissions.
*
+ * @param handler The Handler on whose thread to execute the callbacks of the {@code
+ * callback} object. If a null is provided then the application's main thread will be used.
* @param subscribeConfig The {@link SubscribeConfig} specifying the
* configuration of the requested subscribe session.
* @param callback A {@link WifiNanDiscoverySessionCallback} derived object to be used for
* session event callbacks.
*/
- public void subscribe(@NonNull SubscribeConfig subscribeConfig,
+ public void subscribe(@Nullable Handler handler, @NonNull SubscribeConfig subscribeConfig,
@NonNull WifiNanDiscoverySessionCallback callback) {
WifiNanManager mgr = mMgr.get();
if (mgr == null) {
Log.e(TAG, "publish: called after termination");
return;
}
- mgr.subscribe(mClientId, mLooper, subscribeConfig, callback);
+ mgr.subscribe(mClientId, (handler == null) ? Looper.getMainLooper() : handler.getLooper(),
+ subscribeConfig, callback);
}
/**