From 319e63384280654615e7e7d6fcc961b7fcd135e0 Mon Sep 17 00:00:00 2001 From: Nate Jiang Date: Tue, 6 Aug 2019 17:15:27 -0700 Subject: [NetworkSuggestion] add hidden network from network suggestion Add hidden network from network suggestion to the scan list, make it can be auto connected and appear in the scan result. Bug: 138975620 Test: atest android.net.wifi Test: atest com.android.server.wifi Test: acts WifiNetworkSuggestionTest Merged-In: Ib053b7b33ed01e7da2cff888b0f720f9d6cdb528 Change-Id: Ib4bc9c51ee6e28471aee34fb7737f3659152c7d3 --- .../com/android/server/wifi/ScanRequestProxy.java | 9 ++++--- .../com/android/server/wifi/WifiConfigManager.java | 17 ++++--------- .../server/wifi/WifiConnectivityManager.java | 9 ++++--- .../server/wifi/WifiNetworkSuggestionsManager.java | 28 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 18 deletions(-) (limited to 'service') 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 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 retrieveHiddenNetworkList() { List hiddenList = new ArrayList<>(); List networks = new ArrayList<>(getInternalConfiguredNetworks()); - // Remove any permanently disabled networks or non hidden networks. - Iterator 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 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; @@ -921,6 +927,28 @@ public class WifiNetworkSuggestionsManager { return approvedExtNetworkSuggestions; } + /** + * 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 retrieveHiddenNetworkList() { + List 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. */ -- cgit v1.2.3