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

Commit 271c0373 authored by Etan Cohen's avatar Etan Cohen Committed by Mitchell Wills
Browse files

[NAN] Remove OnNanDown notification from API

Duplicates the WIFI_NAN_STATE_CHANGED_ACTION broadcast. Remove
all state information from manager.

Bug: 28622807
Change-Id: I00632b216edb2dd74412861c4b46f01adec5a271
(cherry picked from commit cbf37593)
parent 31a513b4
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -27,6 +27,5 @@ oneway interface IWifiNanEventCallback
{
{
    void onConnectSuccess();
    void onConnectSuccess();
    void onConnectFail(int reason);
    void onConnectFail(int reason);
    void onNanDown(int reason);
    void onIdentityChanged();
    void onIdentityChanged();
}
}
+2 −18
Original line number Original line Diff line number Diff line
@@ -31,8 +31,8 @@ import java.lang.annotation.RetentionPolicy;
 */
 */
public class WifiNanEventCallback {
public class WifiNanEventCallback {
    @IntDef({
    @IntDef({
            REASON_INVALID_ARGS, REASON_ALREADY_CONNECTED_INCOMPAT_CONFIG, REASON_REQUESTED,
            REASON_INVALID_ARGS, REASON_ALREADY_CONNECTED_INCOMPAT_CONFIG, REASON_OTHER
            REASON_OTHER })
    })
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    public @interface EventReasonCodes {
    public @interface EventReasonCodes {
    }
    }
@@ -52,12 +52,6 @@ public class WifiNanEventCallback {
     */
     */
    public static final int REASON_ALREADY_CONNECTED_INCOMPAT_CONFIG = 1001;
    public static final int REASON_ALREADY_CONNECTED_INCOMPAT_CONFIG = 1001;


    /**
     * Reason flag for {@link WifiNanEventCallback#onNanDown(int)} callback.
     * Indicates NAN is shut-down per user request.
     */
    public static final int REASON_REQUESTED = 1002;

    /**
    /**
     * Failure reason flag for {@link WifiNanEventCallback} callbacks. Indicates
     * Failure reason flag for {@link WifiNanEventCallback} callbacks. Indicates
     * an unspecified error occurred during the operation.
     * an unspecified error occurred during the operation.
@@ -86,16 +80,6 @@ public class WifiNanEventCallback {
        /* empty */
        /* empty */
    }
    }


    /**
     * Called when NAN cluster is down
     *
     * @param reason Reason code for event, see
     *            {@code WifiNanEventCallback.REASON_*}.
     */
    public void onNanDown(@EventReasonCodes int reason) {
        /* empty */
    }

    /**
    /**
     * Called when NAN identity has changed. This may be due to joining a
     * Called when NAN identity has changed. This may be due to joining a
     * cluster, starting a cluster, or discovery interface change. The
     * cluster, starting a cluster, or discovery interface change. The
+33 −89
Original line number Original line Diff line number Diff line
@@ -53,6 +53,8 @@ public class WifiNanManager {
    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


    private static final int INVALID_CLIENT_ID = 0;

    /**
    /**
     * Broadcast intent action to indicate whether Wi-Fi NAN is enabled or
     * Broadcast intent action to indicate whether Wi-Fi NAN is enabled or
     * disabled. An extra {@link #EXTRA_WIFI_STATE} provides the state
     * disabled. An extra {@link #EXTRA_WIFI_STATE} provides the state
@@ -89,27 +91,13 @@ public class WifiNanManager {


    private final IWifiNanManager mService;
    private final IWifiNanManager mService;


    /*
     * State transitions:
     * UNCONNECTED -- (connect()) --> CONNECTING -- (onConnectSuccess()) --> CONNECTED
     * UNCONNECTED -- (connect()) --> CONNECTING -- (onConnectFail()) --> UNCONNECTED
     * CONNECTED||CONNECTING -- (disconnect()) --> UNCONNECTED
     * CONNECTED||CONNECTING -- onNanDown() --> UNCONNECTED
     */
    private static final int STATE_UNCONNECTED = 0;
    private static final int STATE_CONNECTING = 1;
    private static final int STATE_CONNECTED = 2;

    private Object mLock = new Object(); // lock access to the following vars
    private Object mLock = new Object(); // lock access to the following vars


    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private int mState = STATE_UNCONNECTED;
    private final IBinder mBinder = new Binder();


    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private IBinder mBinder;
    private int mClientId = INVALID_CLIENT_ID;

    @GuardedBy("mLock")
    private int mClientId;


    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private Looper mLooper;
    private Looper mLooper;
@@ -122,8 +110,9 @@ public class WifiNanManager {
    }
    }


    /**
    /**
     * Enable the usage of the NAN API. Doesn't actually turn on NAN cluster
     * Enable the usage of the NAN API. Doesn't actually turn on NAN cluster formation - that only
     * formation - that only happens when a connection is made.
     * happens when a connection is made. {@link #WIFI_NAN_STATE_CHANGED_ACTION} broadcast will be
     * triggered.
     *
     *
     * @hide PROPOSED_NAN_SYSTEM_API
     * @hide PROPOSED_NAN_SYSTEM_API
     */
     */
@@ -136,10 +125,9 @@ public class WifiNanManager {
    }
    }


    /**
    /**
     * Disable the usage of the NAN API. All attempts to connect() will be
     * Disable the usage of the NAN API. All attempts to connect() will be rejected. All open
     * rejected. All open connections and sessions will be terminated. The
     * connections and sessions will be terminated. {@link #WIFI_NAN_STATE_CHANGED_ACTION} broadcast
     * {@link WifiNanEventCallback#onNanDown(int)} will be called with reason
     * will be triggered.
     * code {@link WifiNanEventCallback#REASON_REQUESTED}.
     *
     *
     * @hide PROPOSED_NAN_SYSTEM_API
     * @hide PROPOSED_NAN_SYSTEM_API
     */
     */
@@ -199,22 +187,14 @@ public class WifiNanManager {
        }
        }


        synchronized (mLock) {
        synchronized (mLock) {
            if (mState != STATE_UNCONNECTED) {
                Log.e(TAG, "connect(): Calling connect() when state != UNCONNECTED!");
                return;
            }

            mLooper = looper;
            mLooper = looper;
            mBinder = new Binder();
            mState = STATE_CONNECTING;


            try {
            try {
                mClientId = mService.connect(mBinder,
                mClientId = mService.connect(mBinder,
                        new WifiNanEventCallbackProxy(this, looper, callback), configRequest);
                        new WifiNanEventCallbackProxy(this, looper, callback), configRequest);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                mClientId = INVALID_CLIENT_ID;
                mLooper = null;
                mLooper = null;
                mBinder = null;
                mState = STATE_UNCONNECTED;
                throw e.rethrowFromSystemServer();
                throw e.rethrowFromSystemServer();
            }
            }
        }
        }
@@ -235,18 +215,16 @@ public class WifiNanManager {
        IBinder binder;
        IBinder binder;
        int clientId;
        int clientId;
        synchronized (mLock) {
        synchronized (mLock) {
            if (mState == STATE_UNCONNECTED) {
            if (mClientId == INVALID_CLIENT_ID) {
                Log.e(TAG, "disconnect(): called while UNCONNECTED - ignored");
                Log.w(TAG, "disconnect(): called with invalid client ID - not connected first?");
                return;
                return;
            }
            }


            binder = mBinder;
            binder = mBinder;
            clientId = mClientId;
            clientId = mClientId;


            mState = STATE_UNCONNECTED;
            mBinder = null;
            mLooper = null;
            mLooper = null;
            mClientId = 0;
            mClientId = INVALID_CLIENT_ID;
        }
        }


        try {
        try {
@@ -258,10 +236,8 @@ public class WifiNanManager {


    @Override
    @Override
    protected void finalize() throws Throwable {
    protected void finalize() throws Throwable {
        if (mState != STATE_UNCONNECTED) {
        disconnect();
        disconnect();
    }
    }
    }


    /**
    /**
     * Request a NAN publish session. The actual publish session is provided by
     * Request a NAN publish session. The actual publish session is provided by
@@ -283,8 +259,9 @@ public class WifiNanManager {
        int clientId;
        int clientId;
        Looper looper;
        Looper looper;
        synchronized (mLock) {
        synchronized (mLock) {
            if (mState != STATE_CONNECTED) {
            if (mLooper == null || mClientId == INVALID_CLIENT_ID) {
                Log.e(TAG, "publish(): called when not CONNECTED!");
                Log.e(TAG, "publish(): called with null looper or invalid client ID - "
                        + "not connected first?");
                return;
                return;
            }
            }


@@ -307,8 +284,8 @@ public class WifiNanManager {


        int clientId;
        int clientId;
        synchronized (mLock) {
        synchronized (mLock) {
            if (mState != STATE_CONNECTED) {
            if (mClientId == INVALID_CLIENT_ID) {
                Log.e(TAG, "updatePublish(): called when not CONNECTED)!");
                Log.e(TAG, "updatePublish(): called with invalid client ID - not connected first?");
                return;
                return;
            }
            }


@@ -343,8 +320,9 @@ public class WifiNanManager {
        int clientId;
        int clientId;
        Looper looper;
        Looper looper;
        synchronized (mLock) {
        synchronized (mLock) {
            if (mState != STATE_CONNECTED) {
            if (mLooper == null || mClientId == INVALID_CLIENT_ID) {
                Log.e(TAG, "subscribe(): called when not CONNECTED!");
                Log.e(TAG, "subscribe(): called with null looper or invalid client ID - "
                        + "not connected first?");
                return;
                return;
            }
            }


@@ -370,8 +348,9 @@ public class WifiNanManager {


        int clientId;
        int clientId;
        synchronized (mLock) {
        synchronized (mLock) {
            if (mState != STATE_CONNECTED) {
            if (mClientId == INVALID_CLIENT_ID) {
                Log.e(TAG, "updateSubscribe(): called when not CONNECTED!");
                Log.e(TAG,
                        "updateSubscribe(): called with invalid client ID - not connected first?");
                return;
                return;
            }
            }


@@ -393,8 +372,9 @@ public class WifiNanManager {


        int clientId;
        int clientId;
        synchronized (mLock) {
        synchronized (mLock) {
            if (mState != STATE_CONNECTED) {
            if (mClientId == INVALID_CLIENT_ID) {
                Log.e(TAG, "terminateSession(): called when not CONNECTED!");
                Log.e(TAG,
                        "terminateSession(): called with invalid client ID - not connected first?");
                return;
                return;
            }
            }


@@ -420,8 +400,8 @@ public class WifiNanManager {


        int clientId;
        int clientId;
        synchronized (mLock) {
        synchronized (mLock) {
            if (mState != STATE_CONNECTED) {
            if (mClientId == INVALID_CLIENT_ID) {
                Log.e(TAG, "sendMessage(): called when not CONNECTED!");
                Log.e(TAG, "sendMessage(): called with invalid client ID - not connected first?");
                return;
                return;
            }
            }


@@ -438,8 +418,7 @@ public class WifiNanManager {
    private static class WifiNanEventCallbackProxy extends IWifiNanEventCallback.Stub {
    private static class WifiNanEventCallbackProxy extends IWifiNanEventCallback.Stub {
        private static final int CALLBACK_CONNECT_SUCCESS = 0;
        private static final int CALLBACK_CONNECT_SUCCESS = 0;
        private static final int CALLBACK_CONNECT_FAIL = 1;
        private static final int CALLBACK_CONNECT_FAIL = 1;
        private static final int CALLBACK_NAN_DOWN = 2;
        private static final int CALLBACK_IDENTITY_CHANGED = 2;
        private static final int CALLBACK_IDENTITY_CHANGED = 3;


        private final Handler mHandler;
        private final Handler mHandler;


@@ -469,42 +448,16 @@ public class WifiNanManager {


                    switch (msg.what) {
                    switch (msg.what) {
                        case CALLBACK_CONNECT_SUCCESS:
                        case CALLBACK_CONNECT_SUCCESS:
                            synchronized (mgr.mLock) {
                                if (mgr.mState != STATE_CONNECTING) {
                                    Log.w(TAG, "onConnectSuccess indication received but not in "
                                            + "CONNECTING state. Ignoring.");
                                    return;
                                }
                                mgr.mState = STATE_CONNECTED;
                            }
                            originalCallback.onConnectSuccess();
                            originalCallback.onConnectSuccess();
                            break;
                            break;
                        case CALLBACK_CONNECT_FAIL:
                        case CALLBACK_CONNECT_FAIL:
                            synchronized (mgr.mLock) {
                            synchronized (mgr.mLock) {
                                if (mgr.mState != STATE_CONNECTING) {
                                    Log.w(TAG, "onConnectFail indication received but not in "
                                            + "CONNECTING state. Ignoring.");
                                    return;
                                }

                                mgr.mState = STATE_UNCONNECTED;
                                mgr.mBinder = null;
                                mgr.mLooper = null;
                                mgr.mLooper = null;
                                mgr.mClientId = 0;
                                mgr.mClientId = INVALID_CLIENT_ID;
                            }
                            }
                            nanManager.clear();
                            nanManager.clear();
                            originalCallback.onConnectFail(msg.arg1);
                            originalCallback.onConnectFail(msg.arg1);
                            break;
                            break;
                        case CALLBACK_NAN_DOWN:
                            synchronized (mgr.mLock) {
                                mgr.mState = STATE_UNCONNECTED;
                                mgr.mBinder = null;
                                mgr.mLooper = null;
                                mgr.mClientId = 0;
                            }
                            nanManager.clear();
                            originalCallback.onNanDown(msg.arg1);
                            break;
                        case CALLBACK_IDENTITY_CHANGED:
                        case CALLBACK_IDENTITY_CHANGED:
                            originalCallback.onIdentityChanged();
                            originalCallback.onIdentityChanged();
                            break;
                            break;
@@ -530,15 +483,6 @@ public class WifiNanManager {
            mHandler.sendMessage(msg);
            mHandler.sendMessage(msg);
        }
        }


        @Override
        public void onNanDown(int reason) {
            if (VDBG) Log.v(TAG, "onNanDown: reason=" + reason);

            Message msg = mHandler.obtainMessage(CALLBACK_NAN_DOWN);
            msg.arg1 = reason;
            mHandler.sendMessage(msg);
        }

        @Override
        @Override
        public void onIdentityChanged() {
        public void onIdentityChanged() {
            if (VDBG) Log.v(TAG, "onIdentityChanged");
            if (VDBG) Log.v(TAG, "onIdentityChanged");