diff options
author | Roshan Pius <rpius@google.com> | 2017-03-21 08:16:22 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2017-03-21 11:26:08 -0700 |
commit | 35c9c7f7a2f83d81b8d61da834b3960f5b9ffe19 (patch) | |
tree | 1c914286848be6d49f1ce204982ba4f43110f9e9 | |
parent | 56ee240e9e4c6a4967f08faa50cef95bfd5c2949 (diff) |
SupplicantStaIfaceHal: Broadcast bssid change event
Bug: 36451639
Test: Unit tests
Change-Id: Id4dc17fc9b0af1145a264406bf5d540c60c511f2
4 files changed, 59 insertions, 10 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java index 8308b4c0d..0fdcebe7e 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java @@ -32,6 +32,7 @@ import android.hardware.wifi.supplicant.V1_0.ISupplicantIface; import android.hardware.wifi.supplicant.V1_0.ISupplicantNetwork; import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIface; import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback; +import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback.BssidChangeReason; import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork; import android.hardware.wifi.supplicant.V1_0.IfaceType; import android.hardware.wifi.supplicant.V1_0.SupplicantStatus; @@ -1753,9 +1754,7 @@ public class SupplicantStaIfaceHal { String bssidStr = NativeUtil.macAddressFromByteArray(bssid); mWifiMonitor.broadcastSupplicantStateChangeEvent( mIfaceName, mFrameworkNetworkId, wifiSsid, bssidStr, newSupplicantState); - if (newSupplicantState == SupplicantState.ASSOCIATED) { - mWifiMonitor.broadcastAssociationSuccesfulEvent(mIfaceName, bssidStr); - } else if (newSupplicantState == SupplicantState.COMPLETED) { + if (newSupplicantState == SupplicantState.COMPLETED) { mWifiMonitor.broadcastNetworkConnectionEvent( mIfaceName, mFrameworkNetworkId, bssidStr); } @@ -1859,6 +1858,20 @@ public class SupplicantStaIfaceHal { } @Override + public void onBssidChanged(byte reason, byte[/* 6 */] bssid) { + logCallback("onBssidChanged"); + synchronized (mLock) { + if (reason == BssidChangeReason.ASSOC_START) { + mWifiMonitor.broadcastTargetBssidEvent( + mIfaceName, NativeUtil.macAddressFromByteArray(bssid)); + } else if (reason == BssidChangeReason.ASSOC_COMPLETE) { + mWifiMonitor.broadcastAssociatedBssidEvent( + mIfaceName, NativeUtil.macAddressFromByteArray(bssid)); + } + } + } + + @Override public void onEapFailure() { logCallback("onEapFailure"); synchronized (mLock) { diff --git a/service/java/com/android/server/wifi/WifiMonitor.java b/service/java/com/android/server/wifi/WifiMonitor.java index 317d3991c..15ec8fd77 100644 --- a/service/java/com/android/server/wifi/WifiMonitor.java +++ b/service/java/com/android/server/wifi/WifiMonitor.java @@ -499,13 +499,23 @@ public class WifiMonitor { * Broadcast the association success event to all the handlers registered for this event. * * @param iface Name of iface on which this occurred. - * @param bssid BSSID of the access point from which we received the reject. + * @param bssid BSSID of the access point. */ - public void broadcastAssociationSuccesfulEvent(String iface, String bssid) { + public void broadcastAssociatedBssidEvent(String iface, String bssid) { sendMessage(iface, WifiStateMachine.CMD_ASSOCIATED_BSSID, 0, 0, bssid); } /** + * Broadcast the start of association event to all the handlers registered for this event. + * + * @param iface Name of iface on which this occurred. + * @param bssid BSSID of the access point. + */ + public void broadcastTargetBssidEvent(String iface, String bssid) { + sendMessage(iface, WifiStateMachine.CMD_TARGET_BSSID, 0, 0, bssid); + } + + /** * Broadcast the network connection event to all the handlers registered for this event. * * @param iface Name of iface on which this occurred. diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java index d7c3b93e3..de96a7a2a 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java @@ -28,6 +28,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -38,6 +39,7 @@ import android.hardware.wifi.supplicant.V1_0.ISupplicant; import android.hardware.wifi.supplicant.V1_0.ISupplicantIface; import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIface; import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback; +import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback.BssidChangeReason; import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork; import android.hardware.wifi.supplicant.V1_0.IfaceType; import android.hardware.wifi.supplicant.V1_0.SupplicantStatus; @@ -879,8 +881,6 @@ public class SupplicantStaIfaceHalTest { verify(mWifiMonitor).broadcastSupplicantStateChangeEvent( eq(WLAN_IFACE_NAME), eq(frameworkNetworkId), any(WifiSsid.class), eq(BSSID), eq(SupplicantState.ASSOCIATED)); - verify(mWifiMonitor).broadcastAssociationSuccesfulEvent( - eq(WLAN_IFACE_NAME), eq(BSSID)); } /** @@ -1010,6 +1010,32 @@ public class SupplicantStaIfaceHalTest { } /** + * Tests the handling of bssid change notification. + */ + @Test + public void testBssidChangedCallback() throws Exception { + executeAndValidateInitializationSequence(); + assertNotNull(mISupplicantStaIfaceCallback); + + mISupplicantStaIfaceCallback.onBssidChanged( + BssidChangeReason.ASSOC_START, NativeUtil.macAddressToByteArray(BSSID)); + verify(mWifiMonitor).broadcastTargetBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID)); + verify(mWifiMonitor, never()).broadcastAssociatedBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID)); + + reset(mWifiMonitor); + mISupplicantStaIfaceCallback.onBssidChanged( + BssidChangeReason.ASSOC_COMPLETE, NativeUtil.macAddressToByteArray(BSSID)); + verify(mWifiMonitor, never()).broadcastTargetBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID)); + verify(mWifiMonitor).broadcastAssociatedBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID)); + + reset(mWifiMonitor); + mISupplicantStaIfaceCallback.onBssidChanged( + BssidChangeReason.DISASSOC, NativeUtil.macAddressToByteArray(BSSID)); + verify(mWifiMonitor, never()).broadcastTargetBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID)); + verify(mWifiMonitor, never()).broadcastAssociatedBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID)); + } + + /** * Tests the handling of EAP failure notification. */ @Test diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java index 873583954..e9424223d 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java @@ -361,14 +361,14 @@ public class WifiMonitorTest { } /** - * Broadcast association successful test. + * Broadcast associated bssid test. */ @Test - public void testBroadcastAssociationSuccessfulEvent() { + public void testBroadcastAssociatedBssidEvent() { mWifiMonitor.registerHandler( WLAN_IFACE_NAME, WifiStateMachine.CMD_ASSOCIATED_BSSID, mHandlerSpy); String bssid = BSSID; - mWifiMonitor.broadcastAssociationSuccesfulEvent(WLAN_IFACE_NAME, bssid); + mWifiMonitor.broadcastAssociatedBssidEvent(WLAN_IFACE_NAME, bssid); mLooper.dispatchAll(); ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class); |