diff options
3 files changed, 30 insertions, 67 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java index e11017ce3449..f69944006a87 100644 --- a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java +++ b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java @@ -622,6 +622,19 @@ public class AccessPoint implements Comparable<AccessPoint> { return builder.toString(); } + public static String getKey(WifiConfiguration config) { + StringBuilder builder = new StringBuilder(); + + if (TextUtils.isEmpty(config.SSID)) { + builder.append(config.BSSID); + } else { + builder.append(removeDoubleQuotes(config.SSID)); + } + + builder.append(',').append(getSecurity(config)); + return builder.toString(); + } + public String getKey() { return mKey; } diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java index 810d941111ec..fac585e06306 100644 --- a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java +++ b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java @@ -146,7 +146,6 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro // TODO(sghuman): Change this to be keyed on AccessPoint.getKey private final HashMap<String, ScanResult> mScanResultCache = new HashMap<>(); - private Integer mScanId = 0; private NetworkInfo mLastNetworkInfo; private WifiInfo mLastInfo; @@ -450,7 +449,6 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro private void handleResume() { mScanResultCache.clear(); mSeenBssids.clear(); - mScanId = 0; } private Collection<ScanResult> updateScanResultCache(final List<ScanResult> newResults) { @@ -525,7 +523,7 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro /** * Update the internal list of access points. * - * <p>Do not called directly (except for forceUpdate), use {@link #updateAccessPoints()} which + * <p>Do not call directly (except for forceUpdate), use {@link #updateAccessPoints()} which * respects {@link #mStaleScanResults}. */ @GuardedBy("mLock") @@ -534,7 +532,7 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro WifiConfiguration connectionConfig = null; if (mLastInfo != null) { connectionConfig = getWifiConfigurationForNetworkId( - mLastInfo.getNetworkId(), mWifiManager.getConfiguredNetworks()); + mLastInfo.getNetworkId(), configs); } // Swap the current access points into a cached list. @@ -546,38 +544,12 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro accessPoint.clearConfig(); } - /* Lookup table to more quickly update AccessPoints by only considering objects with the - * correct SSID. Maps SSID -> List of AccessPoints with the given SSID. */ - Multimap<String, AccessPoint> existingApMap = new Multimap<String, AccessPoint>(); - final Collection<ScanResult> results = updateScanResultCache(newScanResults); - // TODO(sghuman): This entire block only exists to populate the WifiConfiguration for - // APs, remove and refactor + final Map<String, WifiConfiguration> configsByKey = new ArrayMap(configs.size()); if (configs != null) { for (WifiConfiguration config : configs) { - if (config.selfAdded && config.numAssociation == 0) { - continue; - } - AccessPoint accessPoint = getCachedOrCreate(config, cachedAccessPoints); - if (mLastInfo != null && mLastNetworkInfo != null) { - accessPoint.update(connectionConfig, mLastInfo, mLastNetworkInfo); - } - - // If saved network not present in scan result then set its Rssi to - // UNREACHABLE_RSSI - boolean apFound = false; - for (ScanResult result : results) { - if (result.SSID.equals(accessPoint.getSsidStr())) { - apFound = true; - break; - } - } - if (!apFound) { - accessPoint.setUnreachable(); - } - accessPoints.add(accessPoint); - existingApMap.put(accessPoint.getSsidStr(), accessPoint); + configsByKey.put(AccessPoint.getKey(config), config); } } @@ -613,40 +585,20 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro for (Map.Entry<String, List<ScanResult>> entry : scanResultsByApKey.entrySet()) { // List can not be empty as it is dynamically constructed on each iteration ScanResult firstResult = entry.getValue().get(0); - boolean found = false; - for (AccessPoint accessPoint : existingApMap.getAll(firstResult.SSID)) { - accessPoint.setScanResults(entry.getValue()); - found = true; - break; - } - // Only create a new AP / add to the list if it wasn't already in the saved configs - if (!found) { - AccessPoint accessPoint = - getCachedOrCreate(entry.getValue(), cachedAccessPoints); - if (mLastInfo != null && mLastNetworkInfo != null) { - accessPoint.update(connectionConfig, mLastInfo, mLastNetworkInfo); - } - - // TODO(sghuman): Move isPasspointNetwork logic into AccessPoint.java - if (firstResult.isPasspointNetwork()) { - // Retrieve a WifiConfiguration for a Passpoint provider that matches - // the given ScanResult. This is used for showing that a given AP - // (ScanResult) is available via a Passpoint provider (provider friendly - // name). - try { - WifiConfiguration config = - mWifiManager.getMatchingWifiConfig(firstResult); - if (config != null) { - accessPoint.update(config); - } - } catch (UnsupportedOperationException e) { - // Passpoint not supported on the device. - } - } + AccessPoint accessPoint = + getCachedOrCreate(entry.getValue(), cachedAccessPoints); + if (mLastInfo != null && mLastNetworkInfo != null) { + accessPoint.update(connectionConfig, mLastInfo, mLastNetworkInfo); + } - accessPoints.add(accessPoint); + // Update the matching config if there is one, to populate saved network info + WifiConfiguration config = configsByKey.get(entry.getKey()); + if (config != null) { + accessPoint.update(config); } + + accessPoints.add(accessPoint); } } diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java index 8362ec2270f3..6be4936413b7 100644 --- a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java +++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java @@ -685,6 +685,7 @@ public class WifiTrackerTest { */ @Test public void trackPasspointApWithPasspointDisabled() throws Exception { + // TODO(sghuman): Delete this test and replace with a passpoint test WifiTracker tracker = createMockedWifiTracker(); // Add a Passpoint AP to the scan results. @@ -707,10 +708,7 @@ public class WifiTrackerTest { when(mockWifiManager.getConfiguredNetworks()) .thenReturn(new ArrayList<WifiConfiguration>()); when(mockWifiManager.getScanResults()).thenReturn(results); - doThrow(new UnsupportedOperationException()) - .when(mockWifiManager).getMatchingWifiConfig(any(ScanResult.class)); tracker.forceUpdate(); - verify(mockWifiManager).getMatchingWifiConfig(any(ScanResult.class)); } @Test @@ -756,7 +754,7 @@ public class WifiTrackerTest { tracker.forceUpdate(); verify(mockWifiManager).getConnectionInfo(); - verify(mockWifiManager, times(2)).getConfiguredNetworks(); + verify(mockWifiManager, times(1)).getConfiguredNetworks(); verify(mockConnectivityManager).getNetworkInfo(any(Network.class)); verify(mockWifiListener, never()).onAccessPointsChanged(); // mStaleAccessPoints is true |