From a2949725ba019f99b0b18f7c75ec49ae83af44ba Mon Sep 17 00:00:00 2001 From: David Su Date: Mon, 25 Nov 2019 16:00:36 -0800 Subject: Rename WifiScanner scan types, clean up hidden network - Renamed WifiScanner.TYPE_* to WifiScanner.SCAN_TYPE_* - Converted hiddenNetworks from HiddenNetwork[] to final List Bug: 143614759 Test: atest FrameworksWifiTests Change-Id: Icf2b7040cd3514949c81c29b2cc1615b11d55770 --- .../com/android/server/wifi/ScanRequestProxy.java | 10 +++----- .../com/android/server/wifi/WakeupController.java | 2 +- .../server/wifi/WifiConnectivityManager.java | 10 +++----- .../android/server/wifi/WifiNetworkFactory.java | 11 ++++---- .../wifi/scanner/WifiScanningServiceImpl.java | 29 +++++++++++----------- 5 files changed, 28 insertions(+), 34 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 0a648d4b4..185523904 100644 --- a/service/java/com/android/server/wifi/ScanRequestProxy.java +++ b/service/java/com/android/server/wifi/ScanRequestProxy.java @@ -484,21 +484,19 @@ public class ScanRequestProxy { WifiScanner.ScanSettings settings = new WifiScanner.ScanSettings(); // Scan requests from apps with network settings will be of high accuracy type. if (fromSettingsOrSetupWizard) { - settings.type = WifiScanner.TYPE_HIGH_ACCURACY; + settings.type = WifiScanner.SCAN_TYPE_HIGH_ACCURACY; } // always do full scans settings.band = WifiScanner.WIFI_BAND_BOTH_WITH_DFS; settings.reportEvents = WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN | WifiScanner.REPORT_EVENT_FULL_SCAN_RESULT; if (mScanningForHiddenNetworksEnabled) { + settings.hiddenNetworks.clear(); // retrieve the list of hidden network SSIDs from saved network to scan for, if enabled. - List hiddenNetworkList = - new ArrayList<>(mWifiConfigManager.retrieveHiddenNetworkList()); + settings.hiddenNetworks.addAll(mWifiConfigManager.retrieveHiddenNetworkList()); // retrieve the list of hidden network SSIDs from Network suggestion to scan for. - hiddenNetworkList.addAll( + settings.hiddenNetworks.addAll( mWifiInjector.getWifiNetworkSuggestionsManager().retrieveHiddenNetworkList()); - settings.hiddenNetworks = hiddenNetworkList.toArray( - new WifiScanner.ScanSettings.HiddenNetwork[0]); } mWifiScanner.startScan(settings, new ScanRequestProxyScanListener(), workSource); return true; diff --git a/service/java/com/android/server/wifi/WakeupController.java b/service/java/com/android/server/wifi/WakeupController.java index bf36c9482..b74a25489 100644 --- a/service/java/com/android/server/wifi/WakeupController.java +++ b/service/java/com/android/server/wifi/WakeupController.java @@ -276,7 +276,7 @@ public class WakeupController { Log.d(TAG, "stop()"); mLastDisconnectTimestampMillis = 0; mLastDisconnectInfo = null; - mWifiInjector.getWifiScanner().deregisterScanListener(mScanListener); + mWifiInjector.getWifiScanner().unregisterScanListener(mScanListener); mWakeupOnboarding.onStop(); } diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 1dd0a484e..818cc0a07 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -904,19 +904,17 @@ public class WifiConnectivityManager { isFullBandScan = true; } } - settings.type = WifiScanner.TYPE_HIGH_ACCURACY; // always do high accuracy scans. + settings.type = WifiScanner.SCAN_TYPE_HIGH_ACCURACY; // always do high accuracy scans. settings.band = getScanBand(isFullBandScan); settings.reportEvents = WifiScanner.REPORT_EVENT_FULL_SCAN_RESULT | WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN; settings.numBssidsPerScan = 0; + settings.hiddenNetworks.clear(); // retrieve the list of hidden network SSIDs from saved network to scan for - List hiddenNetworkList = - new ArrayList<>(mConfigManager.retrieveHiddenNetworkList()); + settings.hiddenNetworks.addAll(mConfigManager.retrieveHiddenNetworkList()); // retrieve the list of hidden network SSIDs from Network suggestion to scan for - hiddenNetworkList.addAll( + settings.hiddenNetworks.addAll( mWifiInjector.getWifiNetworkSuggestionsManager().retrieveHiddenNetworkList()); - settings.hiddenNetworks = - hiddenNetworkList.toArray(new ScanSettings.HiddenNetwork[0]); SingleScanListener singleScanListener = new SingleScanListener(isFullBandScan); diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java index 257b5fa9e..a296a2807 100644 --- a/service/java/com/android/server/wifi/WifiNetworkFactory.java +++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java @@ -367,7 +367,7 @@ public class WifiNetworkFactory extends NetworkFactory { mWifiMetrics = wifiMetrics; // Create the scan settings. mScanSettings = new WifiScanner.ScanSettings(); - mScanSettings.type = WifiScanner.TYPE_HIGH_ACCURACY; + mScanSettings.type = WifiScanner.SCAN_TYPE_HIGH_ACCURACY; mScanSettings.band = WifiScanner.WIFI_BAND_BOTH_WITH_DFS; mScanSettings.reportEvents = WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN; mScanListener = new NetworkFactoryScanListener(); @@ -1046,11 +1046,10 @@ public class WifiNetworkFactory extends NetworkFactory { WifiNetworkSpecifier wns = mActiveSpecificNetworkRequestSpecifier; WifiConfiguration wifiConfiguration = wns.wifiConfiguration; if (wifiConfiguration.hiddenSSID) { - mScanSettings.hiddenNetworks = new WifiScanner.ScanSettings.HiddenNetwork[1]; // Can't search for SSID pattern in hidden networks. - mScanSettings.hiddenNetworks[0] = - new WifiScanner.ScanSettings.HiddenNetwork( - addEnclosingQuotes(wns.ssidPatternMatcher.getPath())); + mScanSettings.hiddenNetworks.clear(); + mScanSettings.hiddenNetworks.add(new WifiScanner.ScanSettings.HiddenNetwork( + addEnclosingQuotes(wns.ssidPatternMatcher.getPath()))); } startScan(); } @@ -1061,7 +1060,7 @@ public class WifiNetworkFactory extends NetworkFactory { mPeriodicScanTimerSet = false; } // Clear the hidden networks field after each request. - mScanSettings.hiddenNetworks = null; + mScanSettings.hiddenNetworks.clear(); } private void scheduleNextPeriodicScan() { diff --git a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java index 27efc91fd..8a30d8f90 100644 --- a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java +++ b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java @@ -1010,8 +1010,9 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { } boolean validateScanType(int type) { - return (type == WifiScanner.TYPE_LOW_LATENCY || type == WifiScanner.TYPE_LOW_POWER - || type == WifiScanner.TYPE_HIGH_ACCURACY); + return type == WifiScanner.SCAN_TYPE_LOW_LATENCY + || type == WifiScanner.SCAN_TYPE_LOW_POWER + || type == WifiScanner.SCAN_TYPE_HIGH_ACCURACY; } boolean validateScanRequest(ClientInfo ci, int handler, ScanSettings settings) { @@ -1037,7 +1038,7 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { + " does not have permission to set hidden networks"); return false; } - if (settings.type != WifiScanner.TYPE_LOW_LATENCY) { + if (settings.type != WifiScanner.SCAN_TYPE_LOW_LATENCY) { Log.e(TAG, "Failing single scan because app " + ci.getUid() + " does not have permission to set type"); return false; @@ -1048,11 +1049,11 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { int getNativeScanType(int type) { switch(type) { - case WifiScanner.TYPE_LOW_LATENCY: + case WifiScanner.SCAN_TYPE_LOW_LATENCY: return WifiNative.SCAN_TYPE_LOW_LATENCY; - case WifiScanner.TYPE_LOW_POWER: + case WifiScanner.SCAN_TYPE_LOW_POWER: return WifiNative.SCAN_TYPE_LOW_POWER; - case WifiScanner.TYPE_HIGH_ACCURACY: + case WifiScanner.SCAN_TYPE_HIGH_ACCURACY: return WifiNative.SCAN_TYPE_HIGH_ACCURACY; default: // This should never happen becuase we've validated the incoming type in @@ -1176,12 +1177,10 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { settings.scanType = mergeScanTypes(settings.scanType, getNativeScanType(entry.settings.type)); channels.addChannels(entry.settings); - if (entry.settings.hiddenNetworks != null) { - for (int i = 0; i < entry.settings.hiddenNetworks.length; i++) { - WifiNative.HiddenNetwork hiddenNetwork = new WifiNative.HiddenNetwork(); - hiddenNetwork.ssid = entry.settings.hiddenNetworks[i].ssid; - hiddenNetworkList.add(hiddenNetwork); - } + for (ScanSettings.HiddenNetwork srcNetwork : entry.settings.hiddenNetworks) { + WifiNative.HiddenNetwork hiddenNetwork = new WifiNative.HiddenNetwork(); + hiddenNetwork.ssid = srcNetwork.ssid; + hiddenNetworkList.add(hiddenNetwork); } if ((entry.settings.reportEvents & WifiScanner.REPORT_EVENT_FULL_SCAN_RESULT) != 0) { @@ -2609,11 +2608,11 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { static String getScanTypeString(int type) { switch(type) { - case WifiScanner.TYPE_LOW_LATENCY: + case WifiScanner.SCAN_TYPE_LOW_LATENCY: return "LOW LATENCY"; - case WifiScanner.TYPE_LOW_POWER: + case WifiScanner.SCAN_TYPE_LOW_POWER: return "LOW POWER"; - case WifiScanner.TYPE_HIGH_ACCURACY: + case WifiScanner.SCAN_TYPE_HIGH_ACCURACY: return "HIGH ACCURACY"; default: // This should never happen becuase we've validated the incoming type in -- cgit v1.2.3