diff options
author | Roshan Pius <rpius@google.com> | 2017-05-30 09:44:02 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2017-05-30 10:13:25 -0700 |
commit | 6f91c8e110e38d1856b2006f4d60437dcaade5d8 (patch) | |
tree | 47c76e76932ccd5d285ffb0d34bbcfca180dca2e | |
parent | 3e80f5fa9e07c935c328fd06de555cfd5f43ed26 (diff) |
WifiStateMachine: Reset network ID for WPS
|WifiNative.migrateNetworksFromSupplicant| retrieves the network ID of
the configuration from wpa_supplicant. This is useful for migration of
config store from N to O, but we don't need this network ID information
for WPS operations since the network ID's allocated by wpa_supplicant
will clash with network ID's allocated by framework. So, reset the
network ID before we add it to WifiConfigManager.
Bug: 62156507
Test: Unit tests
Change-Id: I1c24c60dc2de2d039b3c372d52d10d55cc4d0241
-rw-r--r-- | service/java/com/android/server/wifi/WifiStateMachine.java | 6 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 25 |
2 files changed, 26 insertions, 5 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index c687fac0c..7f57316a6 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -6645,8 +6645,12 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss return false; } for (Map.Entry<String, WifiConfiguration> entry : configs.entrySet()) { + WifiConfiguration config = entry.getValue(); + // Reset the network ID retrieved from wpa_supplicant, since we want to treat + // this as a new network addition in framework. + config.networkId = WifiConfiguration.INVALID_NETWORK_ID; NetworkUpdateResult result = mWifiConfigManager.addOrUpdateNetwork( - entry.getValue(), mSourceMessage.sendingUid); + config, mSourceMessage.sendingUid); if (!result.isSuccess()) { loge("Failed to add network after WPS: " + entry.getValue()); return false; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index a2194896d..be9b0c544 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -118,6 +118,8 @@ public class WifiStateMachineTest { (ActivityManager.isLowRamDeviceStatic() ? WifiStateMachine.NUM_LOG_RECS_VERBOSE_LOW_MEMORY : WifiStateMachine.NUM_LOG_RECS_VERBOSE); + private static final int WPS_SUPPLICANT_NETWORK_ID = 5; + private static final int WPS_FRAMEWORK_NETWORK_ID = 10; private static final String DEFAULT_TEST_SSID = "\"GoogleGuest\""; private long mBinderToken; @@ -1384,6 +1386,7 @@ public class WifiStateMachineTest { mLooper.dispatchAll(); assertEquals("DisconnectedState", getCurrentState().getName()); + verifyMocksForWpsNetworkMigration(); } /** @@ -1433,6 +1436,7 @@ public class WifiStateMachineTest { mLooper.dispatchAll(); assertEquals("DisconnectedState", getCurrentState().getName()); + verifyMocksForWpsNetworkMigration(); } /** @@ -1504,21 +1508,34 @@ public class WifiStateMachineTest { } private void setupMocksForWpsNetworkMigration() { - int newNetworkId = 5; // Now trigger the network connection event for adding the WPS network. doAnswer(new AnswerWithArguments() { public boolean answer(Map<String, WifiConfiguration> configs, SparseArray<Map<String, String>> networkExtras) throws Exception { - configs.put("dummy", new WifiConfiguration()); + WifiConfiguration config = new WifiConfiguration(); + config.networkId = WPS_SUPPLICANT_NETWORK_ID; + config.SSID = DEFAULT_TEST_SSID; + configs.put("dummy", config); return true; } }).when(mWifiNative).migrateNetworksFromSupplicant(any(Map.class), any(SparseArray.class)); when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt())) - .thenReturn(new NetworkUpdateResult(newNetworkId)); - when(mWifiConfigManager.enableNetwork(eq(newNetworkId), anyBoolean(), anyInt())) + .thenReturn(new NetworkUpdateResult(WPS_FRAMEWORK_NETWORK_ID)); + when(mWifiConfigManager.enableNetwork(eq(WPS_FRAMEWORK_NETWORK_ID), anyBoolean(), anyInt())) .thenReturn(true); } + private void verifyMocksForWpsNetworkMigration() { + // Network Ids should be reset so that it is treated as addition. + ArgumentCaptor<WifiConfiguration> wifiConfigCaptor = + ArgumentCaptor.forClass(WifiConfiguration.class); + verify(mWifiConfigManager).addOrUpdateNetwork(wifiConfigCaptor.capture(), anyInt()); + assertEquals(WifiConfiguration.INVALID_NETWORK_ID, wifiConfigCaptor.getValue().networkId); + assertEquals(DEFAULT_TEST_SSID, wifiConfigCaptor.getValue().SSID); + verify(mWifiConfigManager).enableNetwork(eq(WPS_FRAMEWORK_NETWORK_ID), anyBoolean(), + anyInt()); + } + /** * Verifies that WifiInfo is cleared upon exiting and entering WifiInfo, and that it is not * updated by SUPPLICAN_STATE_CHANGE_EVENTs in ScanModeState. |