From 21b91439e158c9a5de1db23de56c2cb6d89b3021 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Fri, 20 Mar 2020 16:40:44 +0800 Subject: Wifi: fix inconsistent state in handleSupplicantStateChange Bug: 142814689 Test: atest FrameworksWifiTests Change-Id: I1c91c618bdac249bf5093cc677993f1b063f27f1 --- .../android/server/wifi/ClientModeImplTest.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index 2eae8ca54..aeb49707e 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -4761,4 +4761,38 @@ public class ClientModeImplTest extends WifiBaseTest { assertTrue(WifiSsid.createFromAsciiEncoded(sFilsSsid).equals(wifiInfo.getWifiSsid())); assertEquals("ConnectedState", getCurrentState().getName()); } + + /** + * Tests the wifi info is updated correctly for connecting network. + */ + @Test + public void testWifiInfoOnConnectingNextNetwork() throws Exception { + + mConnectedNetwork.ephemeral = true; + mConnectedNetwork.trusted = true; + mConnectedNetwork.osu = true; + + triggerConnect(); + when(mWifiConfigManager.getScanDetailCacheForNetwork(FRAMEWORK_NETWORK_ID)) + .thenReturn(mScanDetailCache); + + when(mScanDetailCache.getScanDetail(sBSSID)).thenReturn( + getGoogleGuestScanDetail(TEST_RSSI, sBSSID, sFreq)); + when(mScanDetailCache.getScanResult(sBSSID)).thenReturn( + getGoogleGuestScanDetail(TEST_RSSI, sBSSID, sFreq).getScanResult()); + + // before the fist success connection, there is no valid wifi info. + assertEquals(WifiConfiguration.INVALID_NETWORK_ID, mCmi.getWifiInfo().getNetworkId()); + + mCmi.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0, + new StateChangeResult(FRAMEWORK_NETWORK_ID, + sWifiSsid, sBSSID, SupplicantState.ASSOCIATED)); + mLooper.dispatchAll(); + + // retrieve correct wifi info on receiving the supplicant state change event. + assertEquals(FRAMEWORK_NETWORK_ID, mCmi.getWifiInfo().getNetworkId()); + assertEquals(mConnectedNetwork.ephemeral, mCmi.getWifiInfo().isEphemeral()); + assertEquals(mConnectedNetwork.trusted, mCmi.getWifiInfo().isTrusted()); + assertEquals(mConnectedNetwork.osu, mCmi.getWifiInfo().isOsuAp()); + } } -- cgit v1.2.3