summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuang Luong <qal@google.com>2021-09-07 16:03:41 -0700
committerQuang Luong <qal@google.com>2021-09-14 20:58:57 +0000
commit731bcb99abc489f1bcab3740be91b321328c6976 (patch)
tree9b40c399118bfe7f7c34b6c1b679df8a7d87b6c1
parentf801a292176965ddb265007680445a02309d2c7f (diff)
downloadwifi-731bcb99abc489f1bcab3740be91b321328c6976.tar.gz
WifiTracker: Update suggestion user shareablilty after scan
Suggestion entries created without scan results should update their user shareability once scans are availible to query it. Bug: 191730857 Test: atest WifiPickerTrackerTest, manual verification that suggestion created before scans are available remains in picker list after disconnection Change-Id: I0996e109726e856f48337531b0ca8f49ee4763f1 (cherry picked from commit f23dc921f360bc62c143c7ee3f670be2c81b27f3) Merged-In: I0996e109726e856f48337531b0ca8f49ee4763f1
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java15
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java44
2 files changed, 53 insertions, 6 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
index 469e43ce9..e97aa28b6 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
@@ -500,25 +500,28 @@ public class WifiPickerTracker extends BaseWifiTracker {
private void updateSuggestedWifiEntryScans(@NonNull List<ScanResult> scanResults) {
checkNotNull(scanResults, "Scan Result list should not be null!");
+ // Get every ScanResultKey that is user shareable
+ final Set<StandardWifiEntryKey> userSharedEntryKeys =
+ mWifiManager.getWifiConfigForMatchedNetworkSuggestionsSharedWithUser(scanResults)
+ .stream()
+ .map(StandardWifiEntryKey::new)
+ .collect(Collectors.toSet());
+
// Group scans by ScanResultKey key
final Map<ScanResultKey, List<ScanResult>> scanResultsByKey = scanResults.stream()
.filter(scan -> !TextUtils.isEmpty(scan.SSID))
.collect(Collectors.groupingBy(ScanResultKey::new));
- // Iterate through current entries and update each entry's scan results
+ // Iterate through current entries and update each entry's scan results and shareability.
final Set<StandardWifiEntryKey> seenEntryKeys = new ArraySet<>();
mSuggestedWifiEntryCache.forEach(entry -> {
final StandardWifiEntryKey entryKey = entry.getStandardWifiEntryKey();
seenEntryKeys.add(entryKey);
// Update scan results if available, or set to null.
entry.updateScanResultInfo(scanResultsByKey.get(entryKey.getScanResultKey()));
+ entry.setUserShareable(userSharedEntryKeys.contains(entryKey));
});
// Create new StandardWifiEntry objects for each leftover config with scan results.
- final Set<StandardWifiEntryKey> userSharedEntryKeys =
- mWifiManager.getWifiConfigForMatchedNetworkSuggestionsSharedWithUser(scanResults)
- .stream()
- .map(StandardWifiEntryKey::new)
- .collect(Collectors.toSet());
for (StandardWifiEntryKey entryKey : mSuggestedConfigCache.keySet()) {
final ScanResultKey scanKey = entryKey.getScanResultKey();
if (seenEntryKeys.contains(entryKey)
diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java
index 122d4b6f9..dd487e9f6 100644
--- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java
+++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java
@@ -852,6 +852,50 @@ public class WifiPickerTrackerTest {
.count()).isEqualTo(1);
}
+ /**
+ * Tests that a suggestion entry created before scan results are available will be updated to
+ * user shareable after scans become available.
+ */
+ @Test
+ public void testGetWifiEntries_preConnectedSuggestion_becomesUserShareable() {
+ WifiConfiguration suggestionConfig = new WifiConfiguration();
+ suggestionConfig.SSID = "\"ssid\"";
+ suggestionConfig.networkId = 1;
+ suggestionConfig.creatorName = "creator";
+ suggestionConfig.carrierId = 1;
+ suggestionConfig.subscriptionId = 1;
+ suggestionConfig.fromWifiNetworkSuggestion = true;
+ // Initial entries
+ when(mMockWifiManager.getPrivilegedConfiguredNetworks()).thenReturn(
+ Arrays.asList(suggestionConfig));
+ when(mMockWifiInfo.getNetworkId()).thenReturn(suggestionConfig.networkId);
+ when(mMockWifiInfo.getRssi()).thenReturn(-50);
+ when(mMockNetworkInfo.getDetailedState()).thenReturn(NetworkInfo.DetailedState.CONNECTED);
+ final WifiPickerTracker wifiPickerTracker = createTestWifiPickerTracker();
+ wifiPickerTracker.onStart();
+ verify(mMockContext).registerReceiver(mBroadcastReceiverCaptor.capture(),
+ any(), any(), any());
+ mTestLooper.dispatchAll();
+ WifiEntry suggestionEntry = wifiPickerTracker.getConnectedWifiEntry();
+ assertThat(suggestionEntry).isNotNull();
+
+ // Update with user-shareable scan results for the suggestion
+ when(mMockWifiManager.getScanResults()).thenReturn(Collections.singletonList(
+ buildScanResult("ssid", "bssid", START_MILLIS)));
+ when(mMockWifiManager.getWifiConfigForMatchedNetworkSuggestionsSharedWithUser(any()))
+ .thenReturn(Arrays.asList(suggestionConfig));
+ mBroadcastReceiverCaptor.getValue().onReceive(mMockContext,
+ new Intent(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
+ // Disconnect from network to verify its usershareability in the picker list
+ mBroadcastReceiverCaptor.getValue().onReceive(mMockContext,
+ new Intent(WifiManager.NETWORK_STATE_CHANGED_ACTION));
+ mTestLooper.dispatchAll();
+
+ // Suggestion entry should be in picker list now
+ suggestionEntry = wifiPickerTracker.getWifiEntries().get(0);
+ assertThat(suggestionEntry.isSuggestion()).isTrue();
+ }
+
@Test
public void testGetConnectedEntry_alreadyConnectedToPasspoint_returnsPasspointEntry() {
final String fqdn = "fqdn";