diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-12-11 19:24:27 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-12-11 19:24:27 +0000 |
commit | 777251dd7fa6d83202304fcaf75948b41aa3dd92 (patch) | |
tree | 13f1b28e6d055bf1cf0a1c7f572f0360140a1f23 /libs | |
parent | b68a1a123c7f05524c83dcf56fd7a7465d85428e (diff) | |
parent | a0a2a080ee2dc91e0272a90b9471695614bd69b3 (diff) |
Merge "Fix StandardNetworkDetailsTracker crash at onStart"
Diffstat (limited to 'libs')
2 files changed, 31 insertions, 6 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java index 1469fa7a0..8b060eb9b 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java @@ -74,7 +74,7 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker { @Override protected void handleOnStart() { - mScanResultUpdater.update(mWifiManager.getScanResults()); + cacheNewScanResults(); conditionallyUpdateScanResults(true /* lastScanSucceeded */); conditionallyUpdateConfig(); } @@ -133,11 +133,7 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker { long scanAgeWindow = mMaxScanAgeMillis; if (lastScanSucceeded) { - // Scan succeeded, cache new scans - mScanResultUpdater.update(mWifiManager.getScanResults().stream().filter( - scan -> TextUtils.equals( - scanResultToStandardWifiEntryKey(scan), mChosenEntry.getKey())) - .collect(toList())); + cacheNewScanResults(); } else { // Scan failed, increase scan age window to prevent WifiEntry list from // clearing prematurely. @@ -157,4 +153,14 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker { .findAny(); mChosenEntry.updateConfig(optionalConfig.orElse(null)); } + + /** + * Updates ScanResultUpdater with new ScanResults matching mChosenEntry. + */ + private void cacheNewScanResults() { + mScanResultUpdater.update(mWifiManager.getScanResults().stream() + .filter(scan -> TextUtils.equals( + scanResultToStandardWifiEntryKey(scan), mChosenEntry.getKey())) + .collect(toList())); + } } diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardNetworkDetailsTrackerTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardNetworkDetailsTrackerTest.java index 740bbdcef..e4be62939 100644 --- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardNetworkDetailsTrackerTest.java +++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardNetworkDetailsTrackerTest.java @@ -148,6 +148,25 @@ public class StandardNetworkDetailsTrackerTest { * Tests that SCAN_RESULTS_AVAILABLE_ACTION updates the level of the entry. */ @Test + public void testHandleOnStart_scanResultUpdaterUpdateCorrectly() { + final ScanResult chosen = buildScanResult("ssid", "bssid", START_MILLIS); + final String key = scanResultToStandardWifiEntryKey(chosen); + final StandardNetworkDetailsTracker tracker = createTestStandardNetworkDetailsTracker(key); + final ScanResult other = buildScanResult("ssid2", "bssid", START_MILLIS, -50 /* rssi */); + when(mMockWifiManager.getScanResults()).thenReturn(Collections.singletonList(other)); + + //tracker.onStart(); + tracker.handleOnStart(); + + final long invalidCount = tracker.mScanResultUpdater.getScanResults().stream().filter( + scanResult -> !"ssid".equals(scanResult.SSID)).count(); + assertThat(invalidCount).isEqualTo(0); + } + + /** + * Tests that SCAN_RESULTS_AVAILABLE_ACTION updates the level of the entry. + */ + @Test public void testScanResultsAvailableAction_updates_getLevel() { // Starting without any scans available should make level WIFI_LEVEL_UNREACHABLE final ScanResult scan = buildScanResult("ssid", "bssid", START_MILLIS, -50 /* rssi */); |