diff options
author | Roshan Pius <rpius@google.com> | 2016-08-24 13:02:08 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2016-08-26 10:34:07 -0700 |
commit | 674b332946074bba7fae1bb4d0d6d2c72d70f3a8 (patch) | |
tree | 07c755fbde6bc4ce68810e6a44c522e412952fa9 /service | |
parent | 6867feee7608fa47f9f7eb7042459ba55e7d0d21 (diff) |
WifiConfigManagerNew: Add couple of missing methods
Add a couple of methods missing in the new WifiConfigManager to start
integrating it with QNS/ConnectivityManager.
The methods added are:
1. A method to fetch a configured network using configKey.
2. Methods to set/clear the QNS connect choice in networks.
3. Method to check if the provided ssid was in the deletedEphemeralSSID
list.
While there,
1. Refactored the creation of copy of WifiConfiguration objects to be
passed to external modules into a common method.
2. Default |allowedAuthAlgorithms| should be set to OPEN.
BUG: 31009287
TEST: Modified existing unit test for [3]. Didn't add any new tests for
[1] & [2] because they're trivial setters/getters.
Change-Id: Id7fe34393737b2faa3de7d301a62e23d85053fe2
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiConfigManagerNew.java | 104 |
1 files changed, 91 insertions, 13 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. |