diff options
-rw-r--r-- | service/java/com/android/server/wifi/WifiConfigManagerNew.java | 104 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java | 7 |
2 files changed, 96 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManagerNew.java b/service/java/com/android/server/wifi/WifiConfigManagerNew.java index a302df39c..1b8c2918b 100644 --- a/service/java/com/android/server/wifi/WifiConfigManagerNew.java +++ b/service/java/com/android/server/wifi/WifiConfigManagerNew.java @@ -354,6 +354,23 @@ public class WifiConfigManagerNew { } /** + * Helper method to create a copy of the provided internal WifiConfiguration object to be + * passed to external modules. + * + * @param configuration provided WifiConfiguration object. + * @param maskPasswords Mask passwords or not. + * @return Copy of the WifiConfiguration object. + */ + private WifiConfiguration createExternalWifiConfiguration( + WifiConfiguration configuration, boolean maskPasswords) { + WifiConfiguration network = new WifiConfiguration(configuration); + if (maskPasswords) { + maskPasswordsInWifiConfiguration(network); + } + return network; + } + + /** * Fetch the list of currently configured networks maintained in WifiConfigManager. * * This retrieves a copy of the internal configurations maintained by WifiConfigManager and @@ -370,11 +387,7 @@ public class WifiConfigManagerNew { if (savedOnly && config.ephemeral) { continue; } - WifiConfiguration newConfig = new WifiConfiguration(config); - if (maskPasswords) { - maskPasswordsInWifiConfiguration(newConfig); - } - networks.add(newConfig); + networks.add(createExternalWifiConfiguration(config, maskPasswords)); } return networks; } @@ -424,9 +437,24 @@ public class WifiConfigManagerNew { } // Create a new configuration object with the passwords masked to send out to the external // world. - WifiConfiguration network = new WifiConfiguration(config); - maskPasswordsInWifiConfiguration(network); - return network; + return createExternalWifiConfiguration(config, true); + } + + /** + * Retrieves the configured network corresponding to the provided config key with password + * masked. + * + * @param configKey configKey of the requested network. + * @return WifiConfiguration object if found, null otherwise. + */ + public WifiConfiguration getConfiguredNetwork(String configKey) { + WifiConfiguration config = getInternalConfiguredNetwork(configKey); + if (config == null) { + return null; + } + // Create a new configuration object with the passwords masked to send out to the external + // world. + return createExternalWifiConfiguration(config, true); } /** @@ -446,8 +474,7 @@ public class WifiConfigManagerNew { } // Create a new configuration object without the passwords masked to send out to the // external world. - WifiConfiguration network = new WifiConfiguration(config); - return network; + return createExternalWifiConfiguration(config, false); } /** @@ -744,7 +771,6 @@ public class WifiConfigManagerNew { */ private void setDefaultsInWifiConfiguration(WifiConfiguration configuration) { configuration.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); - configuration.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); configuration.allowedProtocols.set(WifiConfiguration.Protocol.RSN); configuration.allowedProtocols.set(WifiConfiguration.Protocol.WPA); @@ -1345,8 +1371,8 @@ public class WifiConfigManagerNew { * {@link NetworkSelectionStatus#mCandidateScore} & * {@link NetworkSelectionStatus#mSeenInLastQualifiedNetworkSelection} for the provided network. * - * This is invoked by Network Selector when it sees a network during network selection procedure to set the - * scan result candidate. + * This is invoked by Network Selector when it sees a network during network selection procedure + * to set the scan result candidate. * * @param networkId network ID corresponding to the network. * @param scanResult Candidate ScanResult associated with this network. @@ -1366,6 +1392,48 @@ public class WifiConfigManagerNew { } /** + * Helper method to clear the {@link NetworkSelectionStatus#mConnectChoice} & + * {@link NetworkSelectionStatus#mConnectChoiceTimestamp} for the provided network. + * + * @param networkId network ID corresponding to the network. + * @return true if the network was found, false otherwise. + */ + public boolean clearNetworkConnectChoice(int networkId) { + WifiConfiguration config = getInternalConfiguredNetwork(networkId); + if (config == null) { + return false; + } + config.getNetworkSelectionStatus().setConnectChoice(null); + config.getNetworkSelectionStatus().setConnectChoiceTimestamp( + NetworkSelectionStatus.INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP); + return true; + } + + /** + * Helper method to set the {@link NetworkSelectionStatus#mConnectChoice} & + * {@link NetworkSelectionStatus#mConnectChoiceTimestamp} for the provided network. + * + * This is invoked by Network Selector when the user overrides the currently connected network + * choice. + * + * @param networkId network ID corresponding to the network. + * @param connectChoiceConfigKey ConfigKey corresponding to the network which was chosen over + * this network. + * @param timestamp timestamp at which the choice was made. + * @return true if the network was found, false otherwise. + */ + public boolean setNetworkConnectChoice( + int networkId, String connectChoiceConfigKey, long timestamp) { + WifiConfiguration config = getInternalConfiguredNetwork(networkId); + if (config == null) { + return false; + } + config.getNetworkSelectionStatus().setConnectChoice(connectChoiceConfigKey); + config.getNetworkSelectionStatus().setConnectChoiceTimestamp(timestamp); + return true; + } + + /** * Helper method to clear out the {@link #mLastNetworkId} user/app network selection. This * is done when either the corresponding network is either removed or disabled. */ @@ -1819,6 +1887,16 @@ public class WifiConfigManagerNew { } /** + * Check if the provided ephemeral network was deleted by the user or not. + * + * @param ssid ssid of the network + * @return true if network was deleted, false otherwise. + */ + public boolean wasEphemeralNetworkDeleted(String ssid) { + return mDeletedEphemeralSSIDs.contains(ssid); + } + + /** * Helper method to clear internal databases. * This method clears the: * - List of configured networks. diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java index 43c446900..ab5da2dff 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java @@ -52,6 +52,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; +import java.util.Set; /** * Unit tests for {@link com.android.server.wifi.WifiConfigManagerNew}. @@ -1809,8 +1810,10 @@ public class WifiConfigManagerNewTest { networks.add(WifiConfigurationTestUtil.createPskNetwork()); networks.add(WifiConfigurationTestUtil.createEapNetwork()); networks.add(WifiConfigurationTestUtil.createWepNetwork()); + String deletedEphemeralSSID = "EphemeralSSID"; + Set<String> deletedEphermalSSIDs = new HashSet<>(Arrays.asList(deletedEphemeralSSID)); WifiConfigStoreDataLegacy storeData = - new WifiConfigStoreDataLegacy(networks, new HashSet<String>()); + new WifiConfigStoreDataLegacy(networks, deletedEphermalSSIDs); // New store files not present, so migrate from the old store. when(mWifiConfigStore.areStoresPresent()).thenReturn(false); @@ -1828,6 +1831,7 @@ public class WifiConfigManagerNewTest { mWifiConfigManager.getConfiguredNetworksWithPasswords(); WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate( networks, retrievedNetworks); + assertTrue(mWifiConfigManager.wasEphemeralNetworkDeleted(deletedEphemeralSSID)); } /** @@ -1899,7 +1903,6 @@ public class WifiConfigManagerNewTest { private void setDefaults(WifiConfiguration configuration) { if (configuration.allowedAuthAlgorithms.isEmpty()) { configuration.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); - configuration.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); } if (configuration.allowedProtocols.isEmpty()) { configuration.allowedProtocols.set(WifiConfiguration.Protocol.RSN); |