Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7fa6ab7f authored by Etan Cohen's avatar Etan Cohen Committed by android-build-merger
Browse files

Merge "[NAN] Add Handler to publish/subscribe per API review" am: 95abef93 am: c8f03c33

am: 3c94a1c5

Change-Id: I3e8726f736066943164bb937f1f3aba6b415e1aa
parents 01a1375c 3c94a1c5
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -58,8 +58,8 @@ import java.util.Arrays;
 * <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
@@ -85,8 +85,8 @@ import java.util.Arrays;
 *     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)}
@@ -330,9 +330,9 @@ public class WifiNanManager {
     * 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}.
     */
@@ -360,12 +360,13 @@ public class WifiNanManager {
     * 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) {
@@ -695,7 +696,7 @@ public class WifiNanManager {
                    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();
+12 −8
Original line number Diff line number Diff line
@@ -41,19 +41,17 @@ public class WifiNanSession {

    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;

@@ -68,7 +66,7 @@ public class WifiNanSession {
     * 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();
@@ -115,12 +113,14 @@ public class WifiNanSession {
     *      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) {
@@ -131,7 +131,8 @@ public class WifiNanSession {
            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);
    }

    /**
@@ -154,12 +155,14 @@ public class WifiNanSession {
     *      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) {
@@ -170,7 +173,8 @@ public class WifiNanSession {
            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);
    }

    /**