Loading packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java +14 −16 Original line number Diff line number Diff line Loading @@ -223,6 +223,8 @@ public class AccessPoint implements Comparable<AccessPoint> { mProviderFriendlyName = savedState.getString(KEY_PROVIDER_FRIENDLY_NAME); } update(mConfig, mInfo, mNetworkInfo); // Do not evict old scan results on initial creation updateRssi(); updateSeen(); mId = sLastId.incrementAndGet(); Loading Loading @@ -442,10 +444,6 @@ public class AccessPoint implements Comparable<AccessPoint> { } private void evictOldScanResults() { if (WifiTracker.sStaleScanResults) { // Do not evict old scan results unless we are scanning and have fresh results. return; } long nowMs = SystemClock.elapsedRealtime(); for (Iterator<ScanResult> iter = mScanResultCache.values().iterator(); iter.hasNext(); ) { ScanResult result = iter.next(); Loading Loading @@ -509,12 +507,8 @@ public class AccessPoint implements Comparable<AccessPoint> { * results, returning the best RSSI for all matching AccessPoints averaged with the previous * value. If the access point is not connected and there are no scan results, the rssi will be * set to {@link #UNREACHABLE_RSSI}. * * <p>Old scan results will be evicted from the cache when this method is invoked. */ private void updateRssi() { evictOldScanResults(); if (this.isActive()) { return; } Loading @@ -533,14 +527,8 @@ public class AccessPoint implements Comparable<AccessPoint> { } } /** * Updates {@link #mSeen} based on the scan result cache. * * <p>Old scan results will be evicted from the cache when this method is invoked. */ /** Updates {@link #mSeen} based on the scan result cache. */ private void updateSeen() { evictOldScanResults(); // TODO(sghuman): Set to now if connected long seen = 0; Loading Loading @@ -1030,12 +1018,22 @@ public class AccessPoint implements Comparable<AccessPoint> { mAccessPointListener = listener; } boolean update(ScanResult result) { /** * Update the AP with the given scan result. * * @param result the ScanResult to add to the AccessPoint scan cache * @param evictOldScanResults whether stale scan results should be removed * from the cache during this update process * @return true if the scan result update caused a change in state which would impact ranking * or AccessPoint rendering (e.g. wifi level, security) */ boolean update(ScanResult result, boolean evictOldScanResults) { if (matches(result)) { int oldLevel = getLevel(); /* Add or update the scan result for the BSSID */ mScanResultCache.put(result.BSSID, result); if (evictOldScanResults) evictOldScanResults(); updateSeen(); updateRssi(); int newLevel = getLevel(); Loading packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java +12 −10 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ public class WifiTracker { Scanner mScanner; @GuardedBy("mLock") static boolean sStaleScanResults = true; private boolean mStaleScanResults = true; public WifiTracker(Context context, WifiListener wifiListener, boolean includeSaved, boolean includeScans) { Loading Loading @@ -354,7 +354,7 @@ public class WifiTracker { * <p>This should always be called when done with a WifiTracker (if startTracking was called) to * ensure proper cleanup and prevent any further callbacks from occurring. * * <p>Calling this method will set the {@link #sStaleScanResults} bit, which prevents * <p>Calling this method will set the {@link #mStaleScanResults} bit, which prevents * {@link WifiListener#onAccessPointsChanged()} callbacks from being invoked (until the bit * is unset on the next SCAN_RESULTS_AVAILABLE_ACTION). */ Loading @@ -372,7 +372,7 @@ public class WifiTracker { mWorkHandler.removePendingMessages(); mMainHandler.removePendingMessages(); sStaleScanResults = true; mStaleScanResults = true; } } Loading Loading @@ -478,14 +478,14 @@ public class WifiTracker { /** * Safely modify {@link #mInternalAccessPoints} by acquiring {@link #mLock} first. * * <p>Will not perform the update if {@link #sStaleScanResults} is true * <p>Will not perform the update if {@link #mStaleScanResults} is true */ private void updateAccessPoints() { List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks(); final List<ScanResult> newScanResults = mWifiManager.getScanResults(); synchronized (mLock) { if(!sStaleScanResults) { if(!mStaleScanResults) { updateAccessPointsLocked(newScanResults, configs); } } Loading @@ -495,7 +495,7 @@ public class WifiTracker { * Update the internal list of access points. * * <p>Do not called directly (except for forceUpdate), use {@link #updateAccessPoints()} which * respects {@link #sStaleScanResults}. * respects {@link #mStaleScanResults}. */ @GuardedBy("mLock") private void updateAccessPointsLocked(final List<ScanResult> newScanResults, Loading Loading @@ -569,7 +569,8 @@ public class WifiTracker { boolean found = false; for (AccessPoint accessPoint : apMap.getAll(result.SSID)) { if (accessPoint.update(result)) { // We want to evict old scan results if are current results are not stale if (accessPoint.update(result, !mStaleScanResults)) { found = true; break; } Loading Loading @@ -642,7 +643,8 @@ public class WifiTracker { for (int i = 0; i < N; i++) { if (cache.get(i).matches(result)) { AccessPoint ret = cache.remove(i); ret.update(result); // evict old scan results only if we have fresh results ret.update(result, !mStaleScanResults); return ret; } } Loading Loading @@ -842,7 +844,7 @@ public class WifiTracker { // Only notify listeners of changes if we have fresh scan results, otherwise the // UI will be updated with stale results. We want to copy the APs regardless, // for instances where forceUpdate was invoked by the caller. if (sStaleScanResults) { if (mStaleScanResults) { copyAndNotifyListeners(false /*notifyListeners*/); } else { copyAndNotifyListeners(true /*notifyListeners*/); Loading Loading @@ -897,7 +899,7 @@ public class WifiTracker { switch (msg.what) { case MSG_UPDATE_ACCESS_POINTS: if (msg.arg1 == CLEAR_STALE_SCAN_RESULTS) { sStaleScanResults = false; mStaleScanResults = false; } updateAccessPoints(); break; Loading packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -247,7 +247,7 @@ public class AccessPointTest { scanResult.BSSID = "bssid"; scanResult.timestamp = SystemClock.elapsedRealtime() * 1000; scanResult.capabilities = ""; assertThat(ap.update(scanResult)).isTrue(); assertThat(ap.update(scanResult, true /* evict old scan results */)).isTrue(); assertThat(ap.getRssi()).isEqualTo(expectedRssi); } Loading packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java +0 −4 Original line number Diff line number Diff line Loading @@ -137,7 +137,6 @@ public class WifiTrackerTest { private Looper mMainLooper; private int mOriginalScoringUiSettingValue; private boolean mOriginalStaleScanResultsValue; @Before public void setUp() { Loading Loading @@ -213,7 +212,6 @@ public class WifiTrackerTest { Settings.Global.NETWORK_SCORING_UI_ENABLED, 1 /* enabled */); mOriginalStaleScanResultsValue = WifiTracker.sStaleScanResults; } @After Loading @@ -222,8 +220,6 @@ public class WifiTrackerTest { InstrumentationRegistry.getTargetContext().getContentResolver(), Settings.Global.NETWORK_SCORING_UI_ENABLED, mOriginalScoringUiSettingValue); WifiTracker.sStaleScanResults = mOriginalStaleScanResultsValue; } private static ScanResult buildScanResult1() { Loading Loading
packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java +14 −16 Original line number Diff line number Diff line Loading @@ -223,6 +223,8 @@ public class AccessPoint implements Comparable<AccessPoint> { mProviderFriendlyName = savedState.getString(KEY_PROVIDER_FRIENDLY_NAME); } update(mConfig, mInfo, mNetworkInfo); // Do not evict old scan results on initial creation updateRssi(); updateSeen(); mId = sLastId.incrementAndGet(); Loading Loading @@ -442,10 +444,6 @@ public class AccessPoint implements Comparable<AccessPoint> { } private void evictOldScanResults() { if (WifiTracker.sStaleScanResults) { // Do not evict old scan results unless we are scanning and have fresh results. return; } long nowMs = SystemClock.elapsedRealtime(); for (Iterator<ScanResult> iter = mScanResultCache.values().iterator(); iter.hasNext(); ) { ScanResult result = iter.next(); Loading Loading @@ -509,12 +507,8 @@ public class AccessPoint implements Comparable<AccessPoint> { * results, returning the best RSSI for all matching AccessPoints averaged with the previous * value. If the access point is not connected and there are no scan results, the rssi will be * set to {@link #UNREACHABLE_RSSI}. * * <p>Old scan results will be evicted from the cache when this method is invoked. */ private void updateRssi() { evictOldScanResults(); if (this.isActive()) { return; } Loading @@ -533,14 +527,8 @@ public class AccessPoint implements Comparable<AccessPoint> { } } /** * Updates {@link #mSeen} based on the scan result cache. * * <p>Old scan results will be evicted from the cache when this method is invoked. */ /** Updates {@link #mSeen} based on the scan result cache. */ private void updateSeen() { evictOldScanResults(); // TODO(sghuman): Set to now if connected long seen = 0; Loading Loading @@ -1030,12 +1018,22 @@ public class AccessPoint implements Comparable<AccessPoint> { mAccessPointListener = listener; } boolean update(ScanResult result) { /** * Update the AP with the given scan result. * * @param result the ScanResult to add to the AccessPoint scan cache * @param evictOldScanResults whether stale scan results should be removed * from the cache during this update process * @return true if the scan result update caused a change in state which would impact ranking * or AccessPoint rendering (e.g. wifi level, security) */ boolean update(ScanResult result, boolean evictOldScanResults) { if (matches(result)) { int oldLevel = getLevel(); /* Add or update the scan result for the BSSID */ mScanResultCache.put(result.BSSID, result); if (evictOldScanResults) evictOldScanResults(); updateSeen(); updateRssi(); int newLevel = getLevel(); Loading
packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java +12 −10 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ public class WifiTracker { Scanner mScanner; @GuardedBy("mLock") static boolean sStaleScanResults = true; private boolean mStaleScanResults = true; public WifiTracker(Context context, WifiListener wifiListener, boolean includeSaved, boolean includeScans) { Loading Loading @@ -354,7 +354,7 @@ public class WifiTracker { * <p>This should always be called when done with a WifiTracker (if startTracking was called) to * ensure proper cleanup and prevent any further callbacks from occurring. * * <p>Calling this method will set the {@link #sStaleScanResults} bit, which prevents * <p>Calling this method will set the {@link #mStaleScanResults} bit, which prevents * {@link WifiListener#onAccessPointsChanged()} callbacks from being invoked (until the bit * is unset on the next SCAN_RESULTS_AVAILABLE_ACTION). */ Loading @@ -372,7 +372,7 @@ public class WifiTracker { mWorkHandler.removePendingMessages(); mMainHandler.removePendingMessages(); sStaleScanResults = true; mStaleScanResults = true; } } Loading Loading @@ -478,14 +478,14 @@ public class WifiTracker { /** * Safely modify {@link #mInternalAccessPoints} by acquiring {@link #mLock} first. * * <p>Will not perform the update if {@link #sStaleScanResults} is true * <p>Will not perform the update if {@link #mStaleScanResults} is true */ private void updateAccessPoints() { List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks(); final List<ScanResult> newScanResults = mWifiManager.getScanResults(); synchronized (mLock) { if(!sStaleScanResults) { if(!mStaleScanResults) { updateAccessPointsLocked(newScanResults, configs); } } Loading @@ -495,7 +495,7 @@ public class WifiTracker { * Update the internal list of access points. * * <p>Do not called directly (except for forceUpdate), use {@link #updateAccessPoints()} which * respects {@link #sStaleScanResults}. * respects {@link #mStaleScanResults}. */ @GuardedBy("mLock") private void updateAccessPointsLocked(final List<ScanResult> newScanResults, Loading Loading @@ -569,7 +569,8 @@ public class WifiTracker { boolean found = false; for (AccessPoint accessPoint : apMap.getAll(result.SSID)) { if (accessPoint.update(result)) { // We want to evict old scan results if are current results are not stale if (accessPoint.update(result, !mStaleScanResults)) { found = true; break; } Loading Loading @@ -642,7 +643,8 @@ public class WifiTracker { for (int i = 0; i < N; i++) { if (cache.get(i).matches(result)) { AccessPoint ret = cache.remove(i); ret.update(result); // evict old scan results only if we have fresh results ret.update(result, !mStaleScanResults); return ret; } } Loading Loading @@ -842,7 +844,7 @@ public class WifiTracker { // Only notify listeners of changes if we have fresh scan results, otherwise the // UI will be updated with stale results. We want to copy the APs regardless, // for instances where forceUpdate was invoked by the caller. if (sStaleScanResults) { if (mStaleScanResults) { copyAndNotifyListeners(false /*notifyListeners*/); } else { copyAndNotifyListeners(true /*notifyListeners*/); Loading Loading @@ -897,7 +899,7 @@ public class WifiTracker { switch (msg.what) { case MSG_UPDATE_ACCESS_POINTS: if (msg.arg1 == CLEAR_STALE_SCAN_RESULTS) { sStaleScanResults = false; mStaleScanResults = false; } updateAccessPoints(); break; Loading
packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -247,7 +247,7 @@ public class AccessPointTest { scanResult.BSSID = "bssid"; scanResult.timestamp = SystemClock.elapsedRealtime() * 1000; scanResult.capabilities = ""; assertThat(ap.update(scanResult)).isTrue(); assertThat(ap.update(scanResult, true /* evict old scan results */)).isTrue(); assertThat(ap.getRssi()).isEqualTo(expectedRssi); } Loading
packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java +0 −4 Original line number Diff line number Diff line Loading @@ -137,7 +137,6 @@ public class WifiTrackerTest { private Looper mMainLooper; private int mOriginalScoringUiSettingValue; private boolean mOriginalStaleScanResultsValue; @Before public void setUp() { Loading Loading @@ -213,7 +212,6 @@ public class WifiTrackerTest { Settings.Global.NETWORK_SCORING_UI_ENABLED, 1 /* enabled */); mOriginalStaleScanResultsValue = WifiTracker.sStaleScanResults; } @After Loading @@ -222,8 +220,6 @@ public class WifiTrackerTest { InstrumentationRegistry.getTargetContext().getContentResolver(), Settings.Global.NETWORK_SCORING_UI_ENABLED, mOriginalScoringUiSettingValue); WifiTracker.sStaleScanResults = mOriginalStaleScanResultsValue; } private static ScanResult buildScanResult1() { Loading