summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java18
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardNetworkDetailsTrackerTest.java19
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 */);