diff options
author | Quang Luong <qal@google.com> | 2020-02-05 12:23:11 -0800 |
---|---|---|
committer | Quang Luong <qal@google.com> | 2020-02-26 01:20:01 +0000 |
commit | 270e37c94bb67b338b3adbf49e6eb2c6ab493464 (patch) | |
tree | c2356cd2de572336dfac647c1fc7ef5f141caf6e /libs | |
parent | 9d62bc1c10c29d162fe7fb94df8c187606f7af76 (diff) |
[WifiTrackerLib] Fix Passpoint entry scan updates
Fixed PasspointWifiEntry handling in wifi picker, saved networks page,
and network details page to update correctly with empty scans when out
of range.
Test: atest WifiTrackerLibTests
Bug: 70983952
Change-Id: I8761aee5b478e3d225e026cb69d21bab69168955
(cherry picked from commit 6d77b880dad02eccb44b5c75d97eaf20de669a27)
Merged-In: I8761aee5b478e3d225e026cb69d21bab69168955
Diffstat (limited to 'libs')
5 files changed, 87 insertions, 15 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java index 5cee304f1..a5b489a72 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java @@ -147,9 +147,13 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker { mChosenEntry.updateScanResultInfo(wifiConfig, pair.second.get(WifiManager.PASSPOINT_HOME_NETWORK), pair.second.get(WifiManager.PASSPOINT_ROAMING_NETWORK)); - break; + return; } } + // No AP in range; set scan results and connection config to null. + mChosenEntry.updateScanResultInfo(null /* wifiConfig */, + null /* homeScanResults */, + null /* roamingScanResults */); } /** diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java index ec16f8d93..4cb790024 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java @@ -340,25 +340,37 @@ public class PasspointWifiEntry extends WifiEntry { } @WorkerThread - void updateScanResultInfo(@NonNull WifiConfiguration wifiConfig, + void updateScanResultInfo(@Nullable WifiConfiguration wifiConfig, @Nullable List<ScanResult> homeScanResults, @Nullable List<ScanResult> roamingScanResults) throws IllegalArgumentException { - mWifiConfig = wifiConfig; - mSecurity = getSecurityTypeFromWifiConfiguration(wifiConfig); mIsRoaming = false; - ScanResult bestScanResult = null; - if (homeScanResults != null && !homeScanResults.isEmpty()) { - bestScanResult = getBestScanResultByLevel(homeScanResults); - } else if (roamingScanResults != null && !roamingScanResults.isEmpty()) { - mIsRoaming = true; - bestScanResult = getBestScanResultByLevel(roamingScanResults); + mWifiConfig = wifiConfig; + mCurrentHomeScanResults.clear(); + mCurrentRoamingScanResults.clear(); + if (homeScanResults != null) { + mCurrentHomeScanResults.addAll(homeScanResults); } - if (bestScanResult == null) { - mLevel = WIFI_LEVEL_UNREACHABLE; + if (roamingScanResults != null) { + mCurrentRoamingScanResults.addAll(roamingScanResults); + } + if (mWifiConfig != null) { + mSecurity = getSecurityTypeFromWifiConfiguration(wifiConfig); + ScanResult bestScanResult = null; + if (homeScanResults != null && !homeScanResults.isEmpty()) { + bestScanResult = getBestScanResultByLevel(homeScanResults); + } else if (roamingScanResults != null && !roamingScanResults.isEmpty()) { + mIsRoaming = true; + bestScanResult = getBestScanResultByLevel(roamingScanResults); + } + if (bestScanResult == null) { + mLevel = WIFI_LEVEL_UNREACHABLE; + } else { + mWifiConfig.SSID = "\"" + bestScanResult.SSID + "\""; + mLevel = mWifiManager.calculateSignalLevel(bestScanResult.level); + } } else { - mWifiConfig.SSID = "\"" + bestScanResult.SSID + "\""; - mLevel = mWifiManager.calculateSignalLevel(bestScanResult.level); + mLevel = WIFI_LEVEL_UNREACHABLE; } notifyOnUpdated(); diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/SavedNetworkTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/SavedNetworkTracker.java index f6016677f..be0c7fd94 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/SavedNetworkTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/SavedNetworkTracker.java @@ -51,6 +51,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import java.util.function.Function; import java.util.stream.Collectors; @@ -217,11 +219,13 @@ public class SavedNetworkTracker extends BaseWifiTracker { private void updatePasspointWifiEntryScans(@NonNull List<ScanResult> scanResults) { checkNotNull(scanResults, "Scan Result list should not be null!"); + Set<String> seenKeys = new TreeSet<>(); List<Pair<WifiConfiguration, Map<Integer, List<ScanResult>>>> matchingWifiConfigs = mWifiManager.getAllMatchingWifiConfigs(scanResults); for (Pair<WifiConfiguration, Map<Integer, List<ScanResult>>> pair : matchingWifiConfigs) { final WifiConfiguration wifiConfig = pair.first; final String key = uniqueIdToPasspointWifiEntryKey(wifiConfig.getKey()); + seenKeys.add(key); // Skip in case we don't have a PasspointWifiEntry for the returned unique identifier. if (!mPasspointWifiEntryCache.containsKey(key)) { continue; @@ -231,6 +235,15 @@ public class SavedNetworkTracker extends BaseWifiTracker { pair.second.get(WifiManager.PASSPOINT_HOME_NETWORK), pair.second.get(WifiManager.PASSPOINT_ROAMING_NETWORK)); } + + for (PasspointWifiEntry entry : mPasspointWifiEntryCache.values()) { + if (!seenKeys.contains(entry.getKey())) { + // No AP in range; set scan results and connection config to null. + entry.updateScanResultInfo(null /* wifiConfig */, + null /* homeScanResults */, + null /* roamingScanResults */); + } + } } /** diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java index e452003f7..7cd83f4a7 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java @@ -62,6 +62,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import java.util.function.Function; import java.util.stream.Collectors; @@ -336,6 +337,7 @@ public class WifiPickerTracker extends BaseWifiTracker { private void updatePasspointWifiEntryScans(@NonNull List<ScanResult> scanResults) { checkNotNull(scanResults, "Scan Result list should not be null!"); + Set<String> seenKeys = new TreeSet<>(); List<Pair<WifiConfiguration, Map<Integer, List<ScanResult>>>> matchingWifiConfigs = mWifiManager.getAllMatchingWifiConfigs(scanResults); for (Pair<WifiConfiguration, Map<Integer, List<ScanResult>>> pair : matchingWifiConfigs) { @@ -345,6 +347,7 @@ public class WifiPickerTracker extends BaseWifiTracker { final List<ScanResult> roamingScans = pair.second.get(WifiManager.PASSPOINT_ROAMING_NETWORK); final String key = uniqueIdToPasspointWifiEntryKey(wifiConfig.getKey()); + seenKeys.add(key); // Skip in case we don't have a Passpoint configuration for the returned unique key if (!mPasspointConfigCache.containsKey(key)) { continue; @@ -362,7 +365,8 @@ public class WifiPickerTracker extends BaseWifiTracker { // Remove entries that are now unreachable mPasspointWifiEntryCache.entrySet() - .removeIf(entry -> entry.getValue().getLevel() == WIFI_LEVEL_UNREACHABLE); + .removeIf(entry -> entry.getValue().getLevel() == WIFI_LEVEL_UNREACHABLE + || !seenKeys.contains(entry.getKey())); } @WorkerThread diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java index 7de9a9e3a..bb69003c7 100644 --- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java +++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java @@ -535,6 +535,45 @@ public class WifiPickerTrackerTest { assertThat(wifiPickerTracker.getWifiEntries().get(0).getTitle()).isEqualTo("friendlyName"); } + /** + * Tests that a PasspointWifiEntry will disappear from getWifiEntries() once it is out of range. + */ + @Test + public void testGetWifiEntries_passpointOutOfRange_returnsNull() { + // Create conditions for one PasspointWifiEntry in getWifiEntries() + final WifiPickerTracker wifiPickerTracker = createTestWifiPickerTracker(); + final PasspointConfiguration passpointConfig = new PasspointConfiguration(); + final HomeSp homeSp = new HomeSp(); + homeSp.setFqdn("fqdn"); + homeSp.setFriendlyName("friendlyName"); + passpointConfig.setHomeSp(homeSp); + passpointConfig.setCredential(new Credential()); + when(mMockWifiManager.getPasspointConfigurations()) + .thenReturn(Collections.singletonList(passpointConfig)); + final WifiConfiguration wifiConfig = spy(new WifiConfiguration()); + when(wifiConfig.getKey()).thenReturn(passpointConfig.getUniqueId()); + final Map<Integer, List<ScanResult>> mapping = new HashMap<>(); + mapping.put(WifiManager.PASSPOINT_HOME_NETWORK, Collections.singletonList( + buildScanResult("ssid", "bssid", START_MILLIS))); + List<Pair<WifiConfiguration, Map<Integer, List<ScanResult>>>> allMatchingWifiConfigs = + Collections.singletonList(new Pair<>(wifiConfig, mapping)); + when(mMockWifiManager.getAllMatchingWifiConfigs(any())).thenReturn(allMatchingWifiConfigs); + wifiPickerTracker.onStart(); + verify(mMockContext).registerReceiver(mBroadcastReceiverCaptor.capture(), + any(), any(), any()); + mTestLooper.dispatchAll(); + + // Age out the scans and get out of range of Passpoint AP + when(mMockClock.millis()).thenReturn(START_MILLIS + MAX_SCAN_AGE_MILLIS + 1); + when(mMockWifiManager.getAllMatchingWifiConfigs(any())).thenReturn(new ArrayList<>()); + mBroadcastReceiverCaptor.getValue().onReceive(mMockContext, + new Intent(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); + + // getWifiEntries() should be empty now + assertThat(wifiPickerTracker.getWifiEntries()).isEmpty(); + + } + @Test public void testGetConnectedEntry_alreadyConnectedToPasspoint_returnsPasspointEntry() { final String fqdn = "fqdn"; |