summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-02-17 13:27:55 -0800
committerRoshan Pius <rpius@google.com>2017-02-21 09:23:36 -0800
commit5317e7c11c99d5cc8417c65cc73cf548f8f52b87 (patch)
tree017ab41cc6bfdbf03d584b5422346ed2ade15acd
parentbcf35be52f93d09a3f2ac8d4272a6d66467309b9 (diff)
SupplicantStaIface: Handle wpa_supplicant death
Trigger the existing WifiMonitor events to indicate establishment/loss of contact with wpa_supplicant. Bug: 33383725 Test: Unit tests Change-Id: I394a3ed7dad4f201456e2aaa53ba380c7a130f33
-rw-r--r--service/java/com/android/server/wifi/SupplicantStaIfaceHal.java1
-rw-r--r--service/java/com/android/server/wifi/WifiMonitor.java28
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java19
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java29
4 files changed, 71 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
index 600c06f6d..64d88f837 100644
--- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
@@ -241,6 +241,7 @@ public class SupplicantStaIfaceHal {
synchronized (mLock) {
mISupplicant = null;
mISupplicantStaIface = null;
+ mWifiMonitor.broadcastSupplicantDisconnectionEvent(mIfaceName);
}
}
diff --git a/service/java/com/android/server/wifi/WifiMonitor.java b/service/java/com/android/server/wifi/WifiMonitor.java
index b95d48ebb..cf2efd4bb 100644
--- a/service/java/com/android/server/wifi/WifiMonitor.java
+++ b/service/java/com/android/server/wifi/WifiMonitor.java
@@ -636,12 +636,12 @@ public class WifiMonitor {
if (ensureConnectedLocked()) {
setMonitoring(iface, true);
- sendMessage(iface, SUP_CONNECTION_EVENT);
+ broadcastSupplicantConnectionEvent(iface);
}
else {
boolean originalMonitoring = isMonitoring(iface);
setMonitoring(iface, true);
- sendMessage(iface, SUP_DISCONNECTION_EVENT);
+ broadcastSupplicantDisconnectionEvent(iface);
setMonitoring(iface, originalMonitoring);
Log.e(TAG, "startMonitoring(" + iface + ") failed!");
}
@@ -650,7 +650,7 @@ public class WifiMonitor {
public synchronized void stopMonitoring(String iface) {
if (mVerboseLoggingEnabled) Log.d(TAG, "stopMonitoring(" + iface + ")");
setMonitoring(iface, true);
- sendMessage(iface, SUP_DISCONNECTION_EVENT);
+ broadcastSupplicantDisconnectionEvent(iface);
setMonitoring(iface, false);
}
@@ -1018,7 +1018,7 @@ public class WifiMonitor {
}
// Notify and exit
- sendMessage(null, SUP_DISCONNECTION_EVENT, eventLogCounter);
+ broadcastSupplicantDisconnectionEvent(null);
return true;
} else if (event == EAP_FAILURE) {
if (eventData.startsWith(EAP_AUTH_FAILURE_STR)) {
@@ -1728,4 +1728,24 @@ public class WifiMonitor {
sendMessage(iface, SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
new StateChangeResult(networkId, wifiSsid, bssid, newSupplicantState));
}
+
+ /**
+ * Broadcast the connection to wpa_supplicant event to all the handlers registered for
+ * this event.
+ *
+ * @param iface Name of iface on which this occurred.
+ */
+ public void broadcastSupplicantConnectionEvent(String iface) {
+ sendMessage(iface, SUP_CONNECTION_EVENT);
+ }
+
+ /**
+ * Broadcast the loss of connection to wpa_supplicant event to all the handlers registered for
+ * this event.
+ *
+ * @param iface Name of iface on which this occurred.
+ */
+ public void broadcastSupplicantDisconnectionEvent(String iface) {
+ sendMessage(iface, SUP_DISCONNECTION_EVENT);
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
index 8b267a955..2b0f4306e 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
@@ -900,6 +900,17 @@ public class SupplicantStaIfaceHalTest {
verify(mWifiMonitor).broadcastWpsOverlapEvent(eq(WLAN_IFACE_NAME));
}
+ /**
+ * Tests the handling of supplicant death notification.
+ */
+ @Test
+ public void testSupplicantDeathCallback() throws Exception {
+ executeAndValidateInitializationSequence();
+ assertNotNull(mDeathRecipientCaptor.getValue());
+
+ mDeathRecipientCaptor.getValue().serviceDied(5L);
+ verify(mWifiMonitor).broadcastSupplicantDisconnectionEvent(eq(WLAN_IFACE_NAME));
+ }
private void executeAndValidateHs20DeauthImminentCallback(boolean isEss) throws Exception {
executeAndValidateInitializationSequence();
@@ -1015,11 +1026,12 @@ public class SupplicantStaIfaceHalTest {
.registerCallback(any(ISupplicantStaIfaceCallback.class));
}
- mInOrder = inOrder(mServiceManagerMock, mISupplicantMock, mISupplicantStaIfaceMock);
+ mInOrder = inOrder(mServiceManagerMock, mISupplicantMock, mISupplicantStaIfaceMock,
+ mWifiMonitor);
// Initialize SupplicantStaIfaceHal, should call serviceManager.registerForNotifications
assertTrue(mDut.initialize());
// verify: service manager initialization sequence
- mInOrder.verify(mServiceManagerMock).linkToDeath(any(IHwBinder.DeathRecipient.class),
+ mInOrder.verify(mServiceManagerMock).linkToDeath(mDeathRecipientCaptor.capture(),
anyLong());
mInOrder.verify(mServiceManagerMock).registerForNotifications(
eq(ISupplicant.kInterfaceName), eq(""), mServiceNotificationCaptor.capture());
@@ -1035,6 +1047,9 @@ public class SupplicantStaIfaceHalTest {
.getInterface(any(ISupplicant.IfaceInfo.class),
any(ISupplicant.getInterfaceCallback.class));
}
+ if (causeRemoteException) {
+ mInOrder.verify(mWifiMonitor).broadcastSupplicantDisconnectionEvent(eq(null));
+ }
if (!causeRemoteException && !getZeroInterfaces && !getNullInterface) {
mInOrder.verify(mISupplicantStaIfaceMock)
.registerCallback(any(ISupplicantStaIfaceCallback.class));
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java
index 8c4021fda..451852a7c 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java
@@ -411,4 +411,33 @@ public class WifiMonitorTest {
assertEquals(bssid, result.BSSID);
assertEquals(newState, result.state);
}
+
+ /**
+ * Broadcast supplicant connection test.
+ */
+ @Test
+ public void testBroadcastSupplicantConnectionEvent() {
+ mWifiMonitor.registerHandler(
+ WLAN_IFACE_NAME, WifiMonitor.SUP_CONNECTION_EVENT, mHandlerSpy);
+ mWifiMonitor.broadcastSupplicantConnectionEvent(WLAN_IFACE_NAME);
+ mLooper.dispatchAll();
+
+ ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
+ verify(mHandlerSpy).handleMessage(messageCaptor.capture());
+ assertEquals(WifiMonitor.SUP_CONNECTION_EVENT, messageCaptor.getValue().what);
+ }
+ /**
+ * Broadcast supplicant disconnection test.
+ */
+ @Test
+ public void testBroadcastSupplicantDisconnectionEvent() {
+ mWifiMonitor.registerHandler(
+ WLAN_IFACE_NAME, WifiMonitor.SUP_DISCONNECTION_EVENT, mHandlerSpy);
+ mWifiMonitor.broadcastSupplicantDisconnectionEvent(WLAN_IFACE_NAME);
+ mLooper.dispatchAll();
+
+ ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
+ verify(mHandlerSpy).handleMessage(messageCaptor.capture());
+ assertEquals(WifiMonitor.SUP_DISCONNECTION_EVENT, messageCaptor.getValue().what);
+ }
}