summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy Chen <jimmycmchen@google.com>2020-03-20 16:40:44 +0800
committerJimmy Chen <jimmycmchen@google.com>2020-03-23 16:04:10 +0800
commit21b91439e158c9a5de1db23de56c2cb6d89b3021 (patch)
tree316f0558a4f84e830cf91443c0c2fdb1bc9076ef
parent5de1f8121f567ac7421cd68c24874e9665cc1178 (diff)
Wifi: fix inconsistent state in handleSupplicantStateChange
Bug: 142814689 Test: atest FrameworksWifiTests Change-Id: I1c91c618bdac249bf5093cc677993f1b063f27f1
-rw-r--r--service/java/com/android/server/wifi/ClientModeImpl.java8
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java34
2 files changed, 40 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index 5da041f8b..3ea695d28 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -2605,8 +2605,12 @@ public class ClientModeImpl extends StateMachine {
// SSID might have been updated, so call updateCapabilities
updateCapabilities();
- final WifiConfiguration config = getCurrentWifiConfiguration();
- if (config != null) {
+ WifiConfiguration config = getCurrentWifiConfiguration();
+ if (config == null) {
+ // If not connected, this should be non-null.
+ config = getTargetWifiConfiguration();
+ }
+ if (config != null && config.networkId == mWifiInfo.getNetworkId()) {
mWifiInfo.setEphemeral(config.ephemeral);
mWifiInfo.setTrusted(config.trusted);
mWifiInfo.setOsuAp(config.osu);
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());
+ }
}