diff options
author | Roshan Pius <rpius@google.com> | 2020-04-22 16:52:46 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2020-04-23 14:36:38 -0700 |
commit | e0e4592a0efe0170ad5a5e162253306f7d0f21fc (patch) | |
tree | 97798c26eacc73f13059eb30cdbee775916d25bc | |
parent | 19df2d0dfa75acecef66737dee97e605bd2b00a3 (diff) |
WifiNetworkFactory: Don't use WifiConfig from UI for matching
The WifiConfiguration passed in from the UI in the
NetworkRequestUserSelectionCallback.select() only has the SSID field
set (in hindsight the select() API should just have accepted a string
param instead of WifiConfiguration). The rest of params including
security params are constructed from the original app's request. Ensure
that we use the merged WifiConfiguration to find matching scan results
to set bssid for connection.
Also, fixed the unit tests to reflect the correct behavior from UI (only
set the SSID field in WifiConfiguration). The unit tests were
incorrectly setting the securiy params and masking the problem.
Bug: 154764757
Test: act.py -c wifi_manager_cross.config -tb dut-name -tc WifiNetworkRequestTest
Test: atest com.android.server.wifi
Change-Id: I611e05f15a0e1fff3cdbc1f6d0e2347653446678
-rw-r--r-- | service/java/com/android/server/wifi/WifiNetworkFactory.java | 8 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java | 28 |
2 files changed, 23 insertions, 13 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java index 26e602354..52fc0e5a7 100644 --- a/service/java/com/android/server/wifi/WifiNetworkFactory.java +++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java @@ -790,7 +790,9 @@ public class WifiNetworkFactory extends NetworkFactory { new WifiConfiguration(mActiveSpecificNetworkRequestSpecifier.wifiConfiguration); networkToConnect.SSID = network.SSID; // Set the WifiConfiguration.BSSID field to prevent roaming. - networkToConnect.BSSID = findBestBssidFromActiveMatchedScanResultsForNetwork(network); + networkToConnect.BSSID = + findBestBssidFromActiveMatchedScanResultsForNetwork( + ScanResultMatchInfo.fromWifiConfiguration(networkToConnect)); networkToConnect.ephemeral = true; // Mark it user private to avoid conflicting with any saved networks the user might have. // TODO (b/142035508): Use a more generic mechanism to fix this. @@ -1246,14 +1248,14 @@ public class WifiNetworkFactory extends NetworkFactory { // i) The latest scan results were empty. // ii) The latest scan result did not contain any BSSID for the SSID user chose. private @Nullable String findBestBssidFromActiveMatchedScanResultsForNetwork( - @NonNull WifiConfiguration network) { + @NonNull ScanResultMatchInfo scanResultMatchInfo) { if (mActiveSpecificNetworkRequestSpecifier == null || mActiveMatchedScanResults == null) return null; ScanResult selectedScanResult = mActiveMatchedScanResults .stream() .filter(scanResult -> Objects.equals( ScanResultMatchInfo.fromScanResult(scanResult), - ScanResultMatchInfo.fromWifiConfiguration(network))) + scanResultMatchInfo)) .max(Comparator.comparing(scanResult -> scanResult.level)) .orElse(null); if (selectedScanResult == null) { // Should never happen. diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java index b495b49c7..ff31eb223 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java @@ -1036,7 +1036,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { // Now trigger user selection to some network. WifiConfiguration selectedNetwork = WifiConfigurationTestUtil.createOpenNetwork(); - networkRequestUserSelectionCallback.select(selectedNetwork); + sendUserSelectionSelect(networkRequestUserSelectionCallback, selectedNetwork); mLooper.dispatchAll(); // Verify we did not attempt to trigger a connection or disable connectivity manager. @@ -1060,7 +1060,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { // Now trigger user selection to some network. WifiConfiguration selectedNetwork = WifiConfigurationTestUtil.createOpenNetwork(); - networkRequestUserSelectionCallback.select(selectedNetwork); + sendUserSelectionSelect(networkRequestUserSelectionCallback, selectedNetwork); mLooper.dispatchAll(); // Verify we did not attempt to trigger a connection or disable connectivity manager. @@ -1082,7 +1082,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { ScanResult matchingScanResult = mTestScanDatas[0].getResults()[0]; mSelectedNetwork = WifiConfigurationTestUtil.createPskNetwork(); mSelectedNetwork.SSID = "\"" + mTestScanDatas[0].getResults()[0].SSID + "\""; - networkRequestUserSelectionCallback.select(mSelectedNetwork); + sendUserSelectionSelect(networkRequestUserSelectionCallback, mSelectedNetwork); mLooper.dispatchAll(); // Cancel periodic scans. @@ -1140,7 +1140,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { // Now trigger user selection to one of the network. mSelectedNetwork = WifiConfigurationTestUtil.createPskNetwork(); mSelectedNetwork.SSID = "\"" + mTestScanDatas[0].getResults()[0].SSID + "\""; - networkRequestUserSelectionCallback.select(mSelectedNetwork); + sendUserSelectionSelect(networkRequestUserSelectionCallback, mSelectedNetwork); mLooper.dispatchAll(); // Verifier num of Approved access points. @@ -1150,7 +1150,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { // Now trigger user selection to another network with different SSID. mSelectedNetwork = WifiConfigurationTestUtil.createPskNetwork(); mSelectedNetwork.SSID = "\"" + mTestScanDatas[0].getResults()[numOfApPerSsid].SSID + "\""; - networkRequestUserSelectionCallback.select(mSelectedNetwork); + sendUserSelectionSelect(networkRequestUserSelectionCallback, mSelectedNetwork); mLooper.dispatchAll(); // Verify triggered trim when user Approved Access Points exceed capacity. @@ -1187,7 +1187,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { .thenReturn(matchingSavedNetwork); // Now trigger user selection to one of the network. - networkRequestUserSelectionCallback.select(mSelectedNetwork); + sendUserSelectionSelect(networkRequestUserSelectionCallback, mSelectedNetwork); mLooper.dispatchAll(); // Cancel periodic scans. @@ -1240,7 +1240,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { INetworkRequestUserSelectionCallback networkRequestUserSelectionCallback = mNetworkRequestUserSelectionCallback.getValue(); assertNotNull(networkRequestUserSelectionCallback); - networkRequestUserSelectionCallback.select(mSelectedNetwork); + sendUserSelectionSelect(networkRequestUserSelectionCallback, mSelectedNetwork); mLooper.dispatchAll(); // Verify WifiConfiguration params. @@ -1291,7 +1291,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { INetworkRequestUserSelectionCallback networkRequestUserSelectionCallback = mNetworkRequestUserSelectionCallback.getValue(); assertNotNull(networkRequestUserSelectionCallback); - networkRequestUserSelectionCallback.select(mSelectedNetwork); + sendUserSelectionSelect(networkRequestUserSelectionCallback, mSelectedNetwork); mLooper.dispatchAll(); // Verify WifiConfiguration params. @@ -1734,7 +1734,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { // Ignore stale callbacks. WifiConfiguration selectedNetwork = WifiConfigurationTestUtil.createOpenNetwork(); - networkRequestUserSelectionCallback.select(selectedNetwork); + sendUserSelectionSelect(networkRequestUserSelectionCallback, selectedNetwork); mLooper.dispatchAll(); verify(mNetworkRequestMatchCallback).onAbort(); @@ -2713,7 +2713,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { // Now trigger user selection to one of the network. mSelectedNetwork = WifiConfigurationTestUtil.createPskNetwork(); mSelectedNetwork.SSID = "\"" + targetSsid + "\""; - networkRequestUserSelectionCallback.select(mSelectedNetwork); + sendUserSelectionSelect(networkRequestUserSelectionCallback, mSelectedNetwork); mLooper.dispatchAll(); // Cancel the periodic scan timer. @@ -3055,4 +3055,12 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { WifiConfigStore.ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION, mock(WifiConfigStoreEncryptionUtil.class)); } + + private void sendUserSelectionSelect(INetworkRequestUserSelectionCallback callback, + WifiConfiguration selectedNetwork) throws RemoteException { + WifiConfiguration selectedNetworkinCb = new WifiConfiguration(); + // only copy over the ssid + selectedNetworkinCb.SSID = selectedNetwork.SSID; + callback.select(selectedNetworkinCb); + } } |