summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-09-07 23:47:24 -0700
committerRebecca Silberstein <silberst@google.com>2017-09-07 23:54:49 -0700
commite416f1b0ebc69d02147f72599fe41d5a045ca2d3 (patch)
tree93e1e220288c0352cdcf2f0a9fff53c19675b81b /tests
parent7fc4bd4bdbe70f4d1e7c471ba008c7c4f9f287e8 (diff)
WifiStateMachine: check for null config after dhcp
If a network config is removed while we are in the ObtainingIpState, we will attempt to get the configured network from WifiConfigManager but it will be null. As we move to the Connected state, this throws a NPE. Instead of moving along to the Connected state, disconnect from the network if we find out we have null for the current config. Also add an additional null check where the NPE was thrown further down the line. Bug: 65257934 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: Ibbce6491970de16cf5265b03398b50a7cdd50ba2
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index c63db86e1..3a8385b4c 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -1571,6 +1571,67 @@ public class WifiStateMachineTest {
}
/**
+ * Test that we disconnect from a network if it was removed while we are in the
+ * ObtainingIpState.
+ */
+ @Test
+ public void disconnectFromNetworkWhenRemovedWhileObtainingIpAddr() throws Exception {
+ initializeAndAddNetworkAndVerifySuccess();
+
+ when(mWifiConfigManager.enableNetwork(eq(0), eq(true), anyInt())).thenReturn(true);
+ when(mWifiConfigManager.checkAndUpdateLastConnectUid(eq(0), anyInt())).thenReturn(true);
+
+ mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
+ mLooper.dispatchAll();
+ verify(mWifiNative).removeAllNetworks();
+
+ mLooper.startAutoDispatch();
+ assertTrue(mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true));
+ mLooper.stopAutoDispatch();
+
+ verify(mWifiConfigManager).enableNetwork(eq(0), eq(true), anyInt());
+ verify(mWifiConnectivityManager).setUserConnectChoice(eq(0));
+ 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());
+
+ mWsm.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, sBSSID);
+ mLooper.dispatchAll();
+
+ mWsm.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
+ new StateChangeResult(0, sWifiSsid, sBSSID, SupplicantState.COMPLETED));
+ mLooper.dispatchAll();
+
+ assertEquals("ObtainingIpState", getCurrentState().getName());
+
+ // now remove the config
+ when(mWifiConfigManager.removeNetwork(eq(FRAMEWORK_NETWORK_ID), anyInt()))
+ .thenReturn(true);
+ mWsm.sendMessage(WifiManager.FORGET_NETWORK, FRAMEWORK_NETWORK_ID, MANAGED_PROFILE_UID);
+ mLooper.dispatchAll();
+ verify(mWifiConfigManager).removeNetwork(eq(FRAMEWORK_NETWORK_ID), anyInt());
+
+ reset(mWifiConfigManager);
+
+ when(mWifiConfigManager.getConfiguredNetwork(FRAMEWORK_NETWORK_ID)).thenReturn(null);
+
+ DhcpResults dhcpResults = new DhcpResults();
+ dhcpResults.setGateway("1.2.3.4");
+ dhcpResults.setIpAddress("192.168.1.100", 0);
+ dhcpResults.addDns("8.8.8.8");
+ dhcpResults.setLeaseDuration(3600);
+
+ injectDhcpSuccess(dhcpResults);
+ mLooper.dispatchAll();
+
+ assertEquals("DisconnectingState", getCurrentState().getName());
+ }
+
+ /**
* Sunny-day scenario for WPS connections. Verifies that after a START_WPS and
* NETWORK_CONNECTION_EVENT command, WifiStateMachine will have transitioned to ObtainingIpState
*/