diff options
author | Arc Wang <arcwang@google.com> | 2019-12-10 19:20:14 +0800 |
---|---|---|
committer | Arc Wang <arcwang@google.com> | 2019-12-11 11:33:47 +0800 |
commit | a0a2a080ee2dc91e0272a90b9471695614bd69b3 (patch) | |
tree | 8171908be1d59afad0c633d290fb681d8d3196f7 | |
parent | 76eb68da2494199b9aff9497baab273d7a914370 (diff) |
Fix StandardNetworkDetailsTracker crash at onStart
Should only update ScanResultUpdater with new ScanResult of the chosen WifiEntry.
Bug: 70983952
Test: atest StandardNetworkDetailsTrackerTest
Change-Id: I3bfaedf77ca1da012349636fe2b1a92b7385ebd6
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 28e315c24..c7052a491 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java @@ -73,7 +73,7 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker { @Override protected void handleOnStart() { - mScanResultUpdater.update(mWifiManager.getScanResults()); + cacheNewScanResults(); conditionallyUpdateScanResults(true /* lastScanSucceeded */); conditionallyUpdateConfig(); } @@ -122,11 +122,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. @@ -146,4 +142,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 */); |