diff options
author | Nate Jiang <qiangjiang@google.com> | 2020-02-25 00:22:59 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-02-25 00:22:59 +0000 |
commit | a41a8b4bace719172bb2721e0b6323bc3830e11d (patch) | |
tree | a0b931b3ed354b7d7e41fa03a1afac40631c4564 /service | |
parent | 861798ec8b5c8770bb883a101ceed513ef7954c4 (diff) | |
parent | 34abfd0239ba324b4f2ec50a7296973b08417e82 (diff) |
Merge changes from topic "addSuggestionPno-rvc-dev" into rvc-dev
* changes:
Move create intenal wificonfig into ExtendedWifiNetworkSuggestion
Add suggestion network to PNO scan list
Diffstat (limited to 'service')
4 files changed, 112 insertions, 72 deletions
diff --git a/service/java/com/android/server/wifi/NetworkSuggestionNominator.java b/service/java/com/android/server/wifi/NetworkSuggestionNominator.java index 61afce1ea..bc5873484 100644 --- a/service/java/com/android/server/wifi/NetworkSuggestionNominator.java +++ b/service/java/com/android/server/wifi/NetworkSuggestionNominator.java @@ -177,8 +177,8 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo ExtendedWifiNetworkSuggestion matchingExtNetworkSuggestion = matchingExtNetworkSuggestionsFromSamePackage.stream().findFirst().get(); // Update the WifiConfigManager with the latest WifiConfig - WifiConfiguration config = createConfigForAddingToWifiConfigManager( - matchingExtNetworkSuggestion, true); + WifiConfiguration config = + matchingExtNetworkSuggestion.createInternalWifiConfiguration(); NetworkUpdateResult result = mWifiConfigManager.addOrUpdateNetwork( config, matchingExtNetworkSuggestion.perAppInfo.uid, @@ -224,8 +224,7 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo if (!ewns.wns.isUserAllowedToManuallyConnect) { continue; } - WifiConfiguration config = - createConfigForAddingToWifiConfigManager(ewns, false); + WifiConfiguration config = ewns.createInternalWifiConfiguration(); WifiConfiguration wCmConfiguredNetwork = mWifiConfigManager.getConfiguredNetwork(config.getKey()); NetworkUpdateResult result = mWifiConfigManager.addOrUpdateNetwork( @@ -256,8 +255,7 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo // Returns the copy of WifiConfiguration with the allocated network ID filled in. private WifiConfiguration addCandidateToWifiConfigManager( @NonNull ExtendedWifiNetworkSuggestion ewns) { - WifiConfiguration wifiConfiguration = - createConfigForAddingToWifiConfigManager(ewns, true); + WifiConfiguration wifiConfiguration = ewns.createInternalWifiConfiguration(); NetworkUpdateResult result = mWifiConfigManager.addOrUpdateNetwork(wifiConfiguration, ewns.perAppInfo.uid, ewns.perAppInfo.packageName); @@ -274,17 +272,6 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo return mWifiConfigManager.getConfiguredNetwork(candidateNetworkId); } - private WifiConfiguration createConfigForAddingToWifiConfigManager( - ExtendedWifiNetworkSuggestion ewns, boolean allowAutojoin) { - WifiConfiguration wifiConfiguration = new WifiConfiguration(ewns.wns.wifiConfiguration); - // Mark the network ephemeral because we don't want these persisted by WifiConfigManager. - wifiConfiguration.ephemeral = true; - wifiConfiguration.fromWifiNetworkSuggestion = true; - wifiConfiguration.allowAutojoin = allowAutojoin; - wifiConfiguration.trusted = !ewns.wns.isNetworkUntrusted; - return wifiConfiguration; - } - @Override public @NominatorId int getId() { return NOMINATOR_ID_SUGGESTION; diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index eb270a0ee..adcfae5e5 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -63,7 +63,6 @@ import java.io.FileDescriptor; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; -import java.util.Arrays; import java.util.BitSet; import java.util.Collection; import java.util.Collections; @@ -198,7 +197,7 @@ public class WifiConfigManager { * have the same |numAssociation|, place the configurations with * |lastSeenInQualifiedNetworkSelection| set first. */ - private static final WifiConfigurationUtil.WifiConfigurationComparator sScanListComparator = + public static final WifiConfigurationUtil.WifiConfigurationComparator sScanListComparator = new WifiConfigurationUtil.WifiConfigurationComparator() { @Override public int compareNetworksWithSameStatus(WifiConfiguration a, WifiConfiguration b) { @@ -2749,58 +2748,6 @@ public class WifiConfigManager { } /** - * Retrieves a list of all the saved networks before enabling disconnected/connected PNO. - * - * PNO network list sent to the firmware has limited size. If there are a lot of saved - * networks, this list will be truncated and we might end up not sending the networks - * with the highest chance of connecting to the firmware. - * So, re-sort the network list based on the frequency of connection to those networks - * and whether it was last seen in the scan results. - * - * @return list of networks in the order of priority. - */ - public List<WifiScanner.PnoSettings.PnoNetwork> retrievePnoNetworkList() { - List<WifiScanner.PnoSettings.PnoNetwork> pnoList = new ArrayList<>(); - List<WifiConfiguration> networks = new ArrayList<>(getInternalConfiguredNetworks()); - // Remove any permanently or temporarily disabled networks. - Iterator<WifiConfiguration> iter = networks.iterator(); - while (iter.hasNext()) { - WifiConfiguration config = iter.next(); - if (config.ephemeral || config.isPasspoint() || !config.allowAutojoin - || config.getNetworkSelectionStatus().isNetworkPermanentlyDisabled() - || config.getNetworkSelectionStatus().isNetworkTemporaryDisabled()) { - iter.remove(); - } - } - if (networks.isEmpty()) { - return pnoList; - } - - // Sort the networks with the most frequent ones at the front of the network list. - Collections.sort(networks, sScanListComparator); - if (mContext.getResources().getBoolean(R.bool.config_wifiPnoRecencySortingEnabled)) { - // Find the most recently connected network and move it to the front of the list. - putMostRecentlyConnectedNetworkAtTop(networks); - } - for (WifiConfiguration config : networks) { - WifiScanner.PnoSettings.PnoNetwork pnoNetwork = - WifiConfigurationUtil.createPnoNetwork(config); - pnoList.add(pnoNetwork); - if (!mContext.getResources().getBoolean(R.bool.config_wifiPnoFrequencyCullingEnabled)) { - continue; - } - WifiScoreCard.PerNetwork network = mWifiScoreCard.lookupNetwork(config.SSID); - List<Integer> channelList = network.getFrequencies(); - pnoNetwork.frequencies = channelList.stream().mapToInt(Integer::intValue).toArray(); - if (mVerboseLoggingEnabled) { - Log.v(TAG, "retrievePnoNetworkList " + pnoNetwork.ssid + ":" - + Arrays.toString(pnoNetwork.frequencies)); - } - } - return pnoList; - } - - /** * Retrieves a list of all the saved hidden networks for scans * * Hidden network list sent to the firmware has limited size. If there are a lot of saved diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 70fe66659..14abdfe99 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -45,6 +45,10 @@ import com.android.wifi.resources.R; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -1087,7 +1091,7 @@ public class WifiConnectivityManager { private void startDisconnectedPnoScan() { // Initialize PNO settings PnoSettings pnoSettings = new PnoSettings(); - List<PnoSettings.PnoNetwork> pnoNetworkList = mConfigManager.retrievePnoNetworkList(); + List<PnoSettings.PnoNetwork> pnoNetworkList = retrievePnoNetworkList(); int listSize = pnoNetworkList.size(); if (listSize == 0) { @@ -1117,6 +1121,68 @@ public class WifiConnectivityManager { mWifiMetrics.logPnoScanStart(); } + /** + * Retrieve the PnoNetworks from Saved and suggestion non-passpoint network. + */ + @VisibleForTesting + public List<PnoSettings.PnoNetwork> retrievePnoNetworkList() { + List<WifiConfiguration> networks = mConfigManager.getSavedNetworks(-1); + networks.addAll(mWifiInjector.getWifiNetworkSuggestionsManager() + .getAllPnoAvailableSuggestionNetworks()); + // remove all auto-join disabled or network selection disabled network. + networks.removeIf(config -> !config.allowAutojoin + || !config.getNetworkSelectionStatus().isNetworkEnabled()); + if (networks.isEmpty()) { + return Collections.EMPTY_LIST; + } + Collections.sort(networks, WifiConfigManager.sScanListComparator); + if (mContext.getResources().getBoolean(R.bool.config_wifiPnoRecencySortingEnabled)) { + // Find the most recently connected network and move it to the front of the list. + putMostRecentlyConnectedNetworkAtTop(networks); + } + WifiScoreCard scoreCard = null; + if (mContext.getResources().getBoolean(R.bool.config_wifiPnoFrequencyCullingEnabled)) { + scoreCard = mWifiInjector.getWifiScoreCard(); + } + + List<PnoSettings.PnoNetwork> pnoList = new ArrayList<>(); + Set<WifiScanner.PnoSettings.PnoNetwork> pnoSet = new HashSet<>(); + for (WifiConfiguration config : networks) { + WifiScanner.PnoSettings.PnoNetwork pnoNetwork = + WifiConfigurationUtil.createPnoNetwork(config); + if (pnoSet.contains(pnoNetwork)) { + continue; + } + pnoList.add(pnoNetwork); + pnoSet.add(pnoNetwork); + if (scoreCard == null) { + continue; + } + WifiScoreCard.PerNetwork network = scoreCard.lookupNetwork(config.SSID); + List<Integer> channelList = network.getFrequencies(); + pnoNetwork.frequencies = channelList.stream().mapToInt(Integer::intValue).toArray(); + localLog("retrievePnoNetworkList " + pnoNetwork.ssid + ":" + + Arrays.toString(pnoNetwork.frequencies)); + } + return pnoList; + } + + /** + * Find the most recently connected network from a list of networks, and place it at top + */ + private void putMostRecentlyConnectedNetworkAtTop(List<WifiConfiguration> networks) { + WifiConfiguration lastConnectedNetwork = + networks.stream() + .max(Comparator.comparing( + (WifiConfiguration config) -> config.lastConnected)) + .get(); + if (lastConnectedNetwork.lastConnected != 0) { + int lastConnectedNetworkIdx = networks.indexOf(lastConnectedNetwork); + networks.remove(lastConnectedNetworkIdx); + networks.add(0, lastConnectedNetwork); + } + } + // Stop PNO scan. private void stopPnoScan() { if (!mPnoScanStarted) return; diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index 204c98773..ad7dc7abb 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -268,6 +268,18 @@ public class WifiNetworkSuggestionsManager { @NonNull PerAppInfo perAppInfo, boolean isAutoJoinEnabled) { return new ExtendedWifiNetworkSuggestion(wns, perAppInfo, isAutoJoinEnabled); } + + /** + * Create a {@link WifiConfiguration} from suggestion for framework internal use. + */ + public WifiConfiguration createInternalWifiConfiguration() { + WifiConfiguration config = new WifiConfiguration(wns.getWifiConfiguration()); + config.ephemeral = true; + config.fromWifiNetworkSuggestion = true; + config.allowAutojoin = isAutojoinEnabled; + config.trusted = !wns.isNetworkUntrusted; + return config; + } } /** @@ -1114,6 +1126,34 @@ public class WifiNetworkSuggestionsManager { .collect(Collectors.toSet()); } + /** + * Get all user approved, non-passpoint networks from suggestion. + */ + public List<WifiConfiguration> getAllPnoAvailableSuggestionNetworks() { + List<WifiConfiguration> networks = new ArrayList<>(); + for (PerAppInfo info : mActiveNetworkSuggestionsPerApp.values()) { + if (!info.hasUserApproved && info.carrierId == TelephonyManager.UNKNOWN_CARRIER_ID) { + continue; + } + for (ExtendedWifiNetworkSuggestion ewns : info.extNetworkSuggestions) { + if (ewns.wns.getPasspointConfiguration() != null) { + continue; + } + WifiConfiguration network = mWifiConfigManager + .getConfiguredNetwork(ewns.wns.getWifiConfiguration().getKey()); + if (network == null) { + network = new WifiConfiguration(ewns.wns.getWifiConfiguration()); + network.ephemeral = true; + network.fromWifiNetworkSuggestion = true; + network.allowAutojoin = ewns.isAutojoinEnabled; + network.trusted = !ewns.wns.isNetworkUntrusted; + } + networks.add(network); + } + } + return networks; + } + private List<Integer> getAllMaxSizes() { return mActiveNetworkSuggestionsPerApp.values() .stream() |