summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wifi/java/android/net/wifi/nan/IWifiNanEventCallback.aidl1
-rw-r--r--wifi/java/android/net/wifi/nan/WifiNanEventCallback.java20
-rw-r--r--wifi/java/android/net/wifi/nan/WifiNanManager.java122
3 files changed, 35 insertions, 108 deletions
diff --git a/wifi/java/android/net/wifi/nan/IWifiNanEventCallback.aidl b/wifi/java/android/net/wifi/nan/IWifiNanEventCallback.aidl
index 1e7f26b446fc..556877a9e3a7 100644
--- a/wifi/java/android/net/wifi/nan/IWifiNanEventCallback.aidl
+++ b/wifi/java/android/net/wifi/nan/IWifiNanEventCallback.aidl
@@ -27,6 +27,5 @@ oneway interface IWifiNanEventCallback
{
void onConnectSuccess();
void onConnectFail(int reason);
- void onNanDown(int reason);
void onIdentityChanged();
}
diff --git a/wifi/java/android/net/wifi/nan/WifiNanEventCallback.java b/wifi/java/android/net/wifi/nan/WifiNanEventCallback.java
index 41290114ffa8..2b9a5fa133b0 100644
--- a/wifi/java/android/net/wifi/nan/WifiNanEventCallback.java
+++ b/wifi/java/android/net/wifi/nan/WifiNanEventCallback.java
@@ -31,8 +31,8 @@ import java.lang.annotation.RetentionPolicy;
*/
public class WifiNanEventCallback {
@IntDef({
- REASON_INVALID_ARGS, REASON_ALREADY_CONNECTED_INCOMPAT_CONFIG, REASON_REQUESTED,
- REASON_OTHER })
+ REASON_INVALID_ARGS, REASON_ALREADY_CONNECTED_INCOMPAT_CONFIG, REASON_OTHER
+ })
@Retention(RetentionPolicy.SOURCE)
public @interface EventReasonCodes {
}
@@ -53,12 +53,6 @@ public class WifiNanEventCallback {
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
* an unspecified error occurred during the operation.
*/
@@ -87,16 +81,6 @@ public class WifiNanEventCallback {
}
/**
- * 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
* cluster, starting a cluster, or discovery interface change. The
* implication is that peers you've been communicating with may no longer
diff --git a/wifi/java/android/net/wifi/nan/WifiNanManager.java b/wifi/java/android/net/wifi/nan/WifiNanManager.java
index bd7d40edc882..8d6396d59632 100644
--- a/wifi/java/android/net/wifi/nan/WifiNanManager.java
+++ b/wifi/java/android/net/wifi/nan/WifiNanManager.java
@@ -53,6 +53,8 @@ public class WifiNanManager {
private static final boolean DBG = false;
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
* disabled. An extra {@link #EXTRA_WIFI_STATE} provides the state
@@ -89,27 +91,13 @@ public class WifiNanManager {
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
@GuardedBy("mLock")
- private int mState = STATE_UNCONNECTED;
+ private final IBinder mBinder = new Binder();
@GuardedBy("mLock")
- private IBinder mBinder;
-
- @GuardedBy("mLock")
- private int mClientId;
+ private int mClientId = INVALID_CLIENT_ID;
@GuardedBy("mLock")
private Looper mLooper;
@@ -122,8 +110,9 @@ public class WifiNanManager {
}
/**
- * Enable the usage of the NAN API. Doesn't actually turn on NAN cluster
- * formation - that only happens when a connection is made.
+ * Enable the usage of the NAN API. Doesn't actually turn on NAN cluster formation - that only
+ * happens when a connection is made. {@link #WIFI_NAN_STATE_CHANGED_ACTION} broadcast will be
+ * triggered.
*
* @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
- * rejected. All open connections and sessions will be terminated. The
- * {@link WifiNanEventCallback#onNanDown(int)} will be called with reason
- * code {@link WifiNanEventCallback#REASON_REQUESTED}.
+ * Disable the usage of the NAN API. All attempts to connect() will be rejected. All open
+ * connections and sessions will be terminated. {@link #WIFI_NAN_STATE_CHANGED_ACTION} broadcast
+ * will be triggered.
*
* @hide PROPOSED_NAN_SYSTEM_API
*/
@@ -199,22 +187,14 @@ public class WifiNanManager {
}
synchronized (mLock) {
- if (mState != STATE_UNCONNECTED) {
- Log.e(TAG, "connect(): Calling connect() when state != UNCONNECTED!");
- return;
- }
-
mLooper = looper;
- mBinder = new Binder();
- mState = STATE_CONNECTING;
try {
mClientId = mService.connect(mBinder,
new WifiNanEventCallbackProxy(this, looper, callback), configRequest);
} catch (RemoteException e) {
+ mClientId = INVALID_CLIENT_ID;
mLooper = null;
- mBinder = null;
- mState = STATE_UNCONNECTED;
e.rethrowAsRuntimeException();
}
}
@@ -235,18 +215,16 @@ public class WifiNanManager {
IBinder binder;
int clientId;
synchronized (mLock) {
- if (mState == STATE_UNCONNECTED) {
- Log.e(TAG, "disconnect(): called while UNCONNECTED - ignored");
+ if (mClientId == INVALID_CLIENT_ID) {
+ Log.w(TAG, "disconnect(): called with invalid client ID - not connected first?");
return;
}
binder = mBinder;
clientId = mClientId;
- mState = STATE_UNCONNECTED;
- mBinder = null;
mLooper = null;
- mClientId = 0;
+ mClientId = INVALID_CLIENT_ID;
}
try {
@@ -258,9 +236,7 @@ public class WifiNanManager {
@Override
protected void finalize() throws Throwable {
- if (mState != STATE_UNCONNECTED) {
- disconnect();
- }
+ disconnect();
}
/**
@@ -283,8 +259,9 @@ public class WifiNanManager {
int clientId;
Looper looper;
synchronized (mLock) {
- if (mState != STATE_CONNECTED) {
- Log.e(TAG, "publish(): called when not CONNECTED!");
+ if (mLooper == null || mClientId == INVALID_CLIENT_ID) {
+ Log.e(TAG, "publish(): called with null looper or invalid client ID - "
+ + "not connected first?");
return;
}
@@ -307,8 +284,8 @@ public class WifiNanManager {
int clientId;
synchronized (mLock) {
- if (mState != STATE_CONNECTED) {
- Log.e(TAG, "updatePublish(): called when not CONNECTED)!");
+ if (mClientId == INVALID_CLIENT_ID) {
+ Log.e(TAG, "updatePublish(): called with invalid client ID - not connected first?");
return;
}
@@ -343,8 +320,9 @@ public class WifiNanManager {
int clientId;
Looper looper;
synchronized (mLock) {
- if (mState != STATE_CONNECTED) {
- Log.e(TAG, "subscribe(): called when not CONNECTED!");
+ if (mLooper == null || mClientId == INVALID_CLIENT_ID) {
+ Log.e(TAG, "subscribe(): called with null looper or invalid client ID - "
+ + "not connected first?");
return;
}
@@ -370,8 +348,9 @@ public class WifiNanManager {
int clientId;
synchronized (mLock) {
- if (mState != STATE_CONNECTED) {
- Log.e(TAG, "updateSubscribe(): called when not CONNECTED!");
+ if (mClientId == INVALID_CLIENT_ID) {
+ Log.e(TAG,
+ "updateSubscribe(): called with invalid client ID - not connected first?");
return;
}
@@ -393,8 +372,9 @@ public class WifiNanManager {
int clientId;
synchronized (mLock) {
- if (mState != STATE_CONNECTED) {
- Log.e(TAG, "terminateSession(): called when not CONNECTED!");
+ if (mClientId == INVALID_CLIENT_ID) {
+ Log.e(TAG,
+ "terminateSession(): called with invalid client ID - not connected first?");
return;
}
@@ -420,8 +400,8 @@ public class WifiNanManager {
int clientId;
synchronized (mLock) {
- if (mState != STATE_CONNECTED) {
- Log.e(TAG, "sendMessage(): called when not CONNECTED!");
+ if (mClientId == INVALID_CLIENT_ID) {
+ Log.e(TAG, "sendMessage(): called with invalid client ID - not connected first?");
return;
}
@@ -438,8 +418,7 @@ public class WifiNanManager {
private static class WifiNanEventCallbackProxy extends IWifiNanEventCallback.Stub {
private static final int CALLBACK_CONNECT_SUCCESS = 0;
private static final int CALLBACK_CONNECT_FAIL = 1;
- private static final int CALLBACK_NAN_DOWN = 2;
- private static final int CALLBACK_IDENTITY_CHANGED = 3;
+ private static final int CALLBACK_IDENTITY_CHANGED = 2;
private final Handler mHandler;
@@ -469,42 +448,16 @@ public class WifiNanManager {
switch (msg.what) {
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();
break;
case CALLBACK_CONNECT_FAIL:
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.mClientId = 0;
+ mgr.mClientId = INVALID_CLIENT_ID;
}
nanManager.clear();
originalCallback.onConnectFail(msg.arg1);
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:
originalCallback.onIdentityChanged();
break;
@@ -531,15 +484,6 @@ public class WifiNanManager {
}
@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
public void onIdentityChanged() {
if (VDBG) Log.v(TAG, "onIdentityChanged");