summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2017-09-28 07:31:47 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2017-09-28 07:31:47 +0000
commita11ca4e24b6d40d4e8266757d2352e0b54ee1160 (patch)
tree37f414a60c8ef5dc65b637053d16627f15232942
parent32b3afda71e106ef11db0dc1c1dccdd7bf509986 (diff)
parent75dc8a494a00a37d19772220fdc639abc05ea3d0 (diff)
downloadandroid_frameworks_opt_net_wifi-a11ca4e24b6d40d4e8266757d2352e0b54ee1160.tar.gz
android_frameworks_opt_net_wifi-a11ca4e24b6d40d4e8266757d2352e0b54ee1160.tar.bz2
android_frameworks_opt_net_wifi-a11ca4e24b6d40d4e8266757d2352e0b54ee1160.zip
release-request-ca7a0f27-e01e-4493-95dc-73b265f88cc9-for-git_oc-mr1-release-4365318 snap-temp-L33600000106883904
Change-Id: I90ee8d18c349171089514d4f2bf523afddfd5cb4
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java13
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java61
2 files changed, 71 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index faad0e2d1..e96c15dad 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -4824,7 +4824,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
// Notify PasspointManager of Passpoint network connected event.
WifiConfiguration currentNetwork = getCurrentWifiConfiguration();
- if (currentNetwork.isPasspoint()) {
+ if (currentNetwork != null && currentNetwork.isPasspoint()) {
mPasspointManager.onPasspointNetworkConnected(currentNetwork.FQDN);
}
}
@@ -5831,8 +5831,15 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
reportConnectionAttemptEnd(
WifiMetrics.ConnectionEvent.FAILURE_NONE,
WifiMetricsProto.ConnectionEvent.HLF_NONE);
- sendConnectedState();
- transitionTo(mConnectedState);
+ if (getCurrentWifiConfiguration() == null) {
+ // The current config may have been removed while we were connecting,
+ // trigger a disconnect to clear up state.
+ mWifiNative.disconnect();
+ transitionTo(mDisconnectingState);
+ } else {
+ sendConnectedState();
+ transitionTo(mConnectedState);
+ }
break;
case CMD_IP_CONFIGURATION_LOST:
// Get Link layer stats so that we get fresh tx packet counters.
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 07840fdac..177261632 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
*/