diff options
Diffstat (limited to 'service')
4 files changed, 45 insertions, 18 deletions
diff --git a/service/java/com/android/server/wifi/ScanRequestProxy.java b/service/java/com/android/server/wifi/ScanRequestProxy.java index efbb7b649..a4678440b 100644 --- a/service/java/com/android/server/wifi/ScanRequestProxy.java +++ b/service/java/com/android/server/wifi/ScanRequestProxy.java @@ -484,11 +484,14 @@ public class ScanRequestProxy { settings.reportEvents = WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN | WifiScanner.REPORT_EVENT_FULL_SCAN_RESULT; if (mScanningForHiddenNetworksEnabled) { - // retrieve the list of hidden network SSIDs to scan for, if enabled. + // retrieve the list of hidden network SSIDs from saved network to scan for, if enabled. List<WifiScanner.ScanSettings.HiddenNetwork> hiddenNetworkList = - mWifiConfigManager.retrieveHiddenNetworkList(); + new ArrayList<>(mWifiConfigManager.retrieveHiddenNetworkList()); + // retrieve the list of hidden network SSIDs from Network suggestion to scan for. + hiddenNetworkList.addAll( + mWifiInjector.getWifiNetworkSuggestionsManager().retrieveHiddenNetworkList()); settings.hiddenNetworks = hiddenNetworkList.toArray( - new WifiScanner.ScanSettings.HiddenNetwork[hiddenNetworkList.size()]); + new WifiScanner.ScanSettings.HiddenNetwork[0]); } mWifiScanner.startScan(settings, new ScanRequestProxyScanListener(), workSource); return true; diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index bda1eb7d2..aa59f251b 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -2685,7 +2685,7 @@ public class WifiConfigManager { } /** - * Retrieves a list of all the saved hidden networks for scans. + * 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 * networks, this list will be truncated and we might end up not sending the networks @@ -2698,19 +2698,12 @@ public class WifiConfigManager { public List<WifiScanner.ScanSettings.HiddenNetwork> retrieveHiddenNetworkList() { List<WifiScanner.ScanSettings.HiddenNetwork> hiddenList = new ArrayList<>(); List<WifiConfiguration> networks = new ArrayList<>(getInternalConfiguredNetworks()); - // Remove any permanently disabled networks or non hidden networks. - Iterator<WifiConfiguration> iter = networks.iterator(); - while (iter.hasNext()) { - WifiConfiguration config = iter.next(); - if (!config.hiddenSSID) { - iter.remove(); - } - } - Collections.sort(networks, sScanListComparator); + // Remove any non hidden networks. + networks.removeIf(config -> !config.hiddenSSID); + networks.sort(sScanListComparator); // The most frequently connected network has the highest priority now. for (WifiConfiguration config : networks) { - hiddenList.add( - new WifiScanner.ScanSettings.HiddenNetwork(config.SSID)); + hiddenList.add(new WifiScanner.ScanSettings.HiddenNetwork(config.SSID)); } return hiddenList; } diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 7411422e0..2e4b5c891 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -916,11 +916,14 @@ public class WifiConnectivityManager { settings.reportEvents = WifiScanner.REPORT_EVENT_FULL_SCAN_RESULT | WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN; settings.numBssidsPerScan = 0; - + // retrieve the list of hidden network SSIDs from saved network to scan for List<ScanSettings.HiddenNetwork> hiddenNetworkList = - mConfigManager.retrieveHiddenNetworkList(); + new ArrayList<>(mConfigManager.retrieveHiddenNetworkList()); + // retrieve the list of hidden network SSIDs from Network suggestion to scan for + hiddenNetworkList.addAll( + mWifiInjector.getWifiNetworkSuggestionsManager().retrieveHiddenNetworkList()); settings.hiddenNetworks = - hiddenNetworkList.toArray(new ScanSettings.HiddenNetwork[hiddenNetworkList.size()]); + hiddenNetworkList.toArray(new ScanSettings.HiddenNetwork[0]); SingleScanListener singleScanListener = new SingleScanListener(isFullBandScan); diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index 5ed0b7bdc..c30d78a08 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -37,6 +37,7 @@ import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.net.wifi.WifiNetworkSuggestion; +import android.net.wifi.WifiScanner; import android.os.Handler; import android.os.UserHandle; import android.text.TextUtils; @@ -51,6 +52,7 @@ import com.android.server.wifi.util.WifiPermissionsUtil; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -90,6 +92,10 @@ public class WifiNetworkSuggestionsManager { @VisibleForTesting public static final String EXTRA_UID = "com.android.server.wifi.extra.NetworkSuggestion.UID"; + /** + * Limit number of hidden networks attach to scan + */ + private static final int NUMBER_OF_HIDDEN_NETWORK_FOR_ONE_SCAN = 100; private final Context mContext; private final Resources mResources; @@ -922,6 +928,28 @@ public class WifiNetworkSuggestionsManager { } /** + * Get hidden network from active network suggestions. + * Todo(): Now limit by a fixed number, maybe we can try rotation? + * @return set of WifiConfigurations + */ + public List<WifiScanner.ScanSettings.HiddenNetwork> retrieveHiddenNetworkList() { + List<WifiScanner.ScanSettings.HiddenNetwork> hiddenNetworks = new ArrayList<>(); + for (PerAppInfo appInfo : mActiveNetworkSuggestionsPerApp.values()) { + if (!appInfo.hasUserApproved) continue; + for (ExtendedWifiNetworkSuggestion ewns : appInfo.extNetworkSuggestions) { + if (!ewns.wns.wifiConfiguration.hiddenSSID) continue; + hiddenNetworks.add( + new WifiScanner.ScanSettings.HiddenNetwork( + ewns.wns.wifiConfiguration.SSID)); + if (hiddenNetworks.size() >= NUMBER_OF_HIDDEN_NETWORK_FOR_ONE_SCAN) { + return hiddenNetworks; + } + } + } + return hiddenNetworks; + } + + /** * Helper method to send the post connection broadcast to specified package. */ private void sendPostConnectionBroadcast( |