summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiMonitor.java33
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java45
2 files changed, 75 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/WifiMonitor.java b/service/java/com/android/server/wifi/WifiMonitor.java
index cc9ce9c0b..3f52c59d1 100644
--- a/service/java/com/android/server/wifi/WifiMonitor.java
+++ b/service/java/com/android/server/wifi/WifiMonitor.java
@@ -828,13 +828,13 @@ public class WifiMonitor {
if (!eventStr.startsWith(EVENT_PREFIX_STR)) {
if (eventStr.startsWith(WPS_SUCCESS_STR)) {
- sendMessage(iface, WPS_SUCCESS_EVENT);
+ broadcastWpsSuccessEvent(iface);
} else if (eventStr.startsWith(WPS_FAIL_STR)) {
handleWpsFailEvent(eventStr, iface);
} else if (eventStr.startsWith(WPS_OVERLAP_STR)) {
- sendMessage(iface, WPS_OVERLAP_EVENT);
+ broadcastWpsOverlapEvent(iface);
} else if (eventStr.startsWith(WPS_TIMEOUT_STR)) {
- sendMessage(iface, WPS_TIMEOUT_EVENT);
+ broadcastWpsTimeoutEvent(iface);
} else if (eventStr.startsWith(P2P_EVENT_PREFIX_STR)) {
handleP2pEvents(eventStr, iface);
} else if (eventStr.startsWith(HOST_AP_EVENT_PREFIX_STR)) {
@@ -1498,4 +1498,31 @@ public class WifiMonitor {
//For all other errors, return a generic internal error
sendMessage(iface, WPS_FAIL_EVENT, WifiManager.ERROR, reason);
}
+
+ /**
+ * Broadcast the WPS succes event to all the handlers registered for this event.
+ *
+ * @param iface Name of iface on which this occurred.
+ */
+ public void broadcastWpsSuccessEvent(String iface) {
+ sendMessage(iface, WPS_SUCCESS_EVENT);
+ }
+
+ /**
+ * Broadcast the WPS overlap event to all the handlers registered for this event.
+ *
+ * @param iface Name of iface on which this occurred.
+ */
+ public void broadcastWpsOverlapEvent(String iface) {
+ sendMessage(iface, WPS_OVERLAP_EVENT);
+ }
+
+ /**
+ * Broadcast the WPS timeout event to all the handlers registered for this event.
+ *
+ * @param iface Name of iface on which this occurred.
+ */
+ public void broadcastWpsTimeoutEvent(String iface) {
+ sendMessage(iface, WPS_TIMEOUT_EVENT);
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java
index 623ec7ff4..f15e41628 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java
@@ -145,4 +145,49 @@ public class WifiMonitorTest {
assertEquals(WifiManager.ERROR, messageCaptor.getValue().arg1);
assertEquals(WpsConfigError.MSG_TIMEOUT, messageCaptor.getValue().arg2);
}
+
+ /**
+ * Broadcast WPS success event test.
+ */
+ @Test
+ public void testBroadcastWpsEventSuccess() {
+ mWifiMonitor.registerHandler(
+ WLAN_IFACE_NAME, WifiMonitor.WPS_SUCCESS_EVENT, mHandlerSpy);
+ mWifiMonitor.broadcastWpsSuccessEvent(WLAN_IFACE_NAME);
+ mLooper.dispatchAll();
+
+ ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
+ verify(mHandlerSpy).handleMessage(messageCaptor.capture());
+ assertEquals(WifiMonitor.WPS_SUCCESS_EVENT, messageCaptor.getValue().what);
+ }
+
+ /**
+ * Broadcast WPS overlap event test.
+ */
+ @Test
+ public void testBroadcastWpsEventOverlap() {
+ mWifiMonitor.registerHandler(
+ WLAN_IFACE_NAME, WifiMonitor.WPS_OVERLAP_EVENT, mHandlerSpy);
+ mWifiMonitor.broadcastWpsOverlapEvent(WLAN_IFACE_NAME);
+ mLooper.dispatchAll();
+
+ ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
+ verify(mHandlerSpy).handleMessage(messageCaptor.capture());
+ assertEquals(WifiMonitor.WPS_OVERLAP_EVENT, messageCaptor.getValue().what);
+ }
+
+ /**
+ * Broadcast WPS timeout event test.
+ */
+ @Test
+ public void testBroadcastWpsEventTimeout() {
+ mWifiMonitor.registerHandler(
+ WLAN_IFACE_NAME, WifiMonitor.WPS_TIMEOUT_EVENT, mHandlerSpy);
+ mWifiMonitor.broadcastWpsTimeoutEvent(WLAN_IFACE_NAME);
+ mLooper.dispatchAll();
+
+ ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
+ verify(mHandlerSpy).handleMessage(messageCaptor.capture());
+ assertEquals(WifiMonitor.WPS_TIMEOUT_EVENT, messageCaptor.getValue().what);
+ }
}