summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorQuang Luong <qal@google.com>2020-08-12 17:03:32 -0700
committerQuang Luong <qal@google.com>2020-08-13 09:02:07 -0700
commit96dd54c7507f9a5b94dd91719e83f5059e0c8c7d (patch)
tree308af03fe2f26ef1be17bd09d1ba9f7181c383a3 /libs
parent1252c1e8cd21a9b5878c2bdff1f9c1d234b74745 (diff)
[WifiTrackerLib] Don't remove connected passpoint entry with no scans
Connected Passpoint entries should not be removed from the wifi picker list if they aren't seen in the scan results. Bug: 162911670 Test: atest WifiPickerTrackerTest Change-Id: I15a6d321659160aceddd428310f6b4c564c3058a
Diffstat (limited to 'libs')
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java3
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java46
2 files changed, 47 insertions, 2 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
index bb3a2246a..0a9bc5634 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
@@ -491,7 +491,8 @@ public class WifiPickerTracker extends BaseWifiTracker {
// Remove entries that are now unreachable
mPasspointWifiEntryCache.entrySet()
.removeIf(entry -> entry.getValue().getLevel() == WIFI_LEVEL_UNREACHABLE
- || !seenKeys.contains(entry.getKey()));
+ || (!seenKeys.contains(entry.getKey()))
+ && entry.getValue().getConnectedState() == CONNECTED_STATE_DISCONNECTED);
}
@WorkerThread
diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java
index feec984bf..553b731d4 100644
--- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java
+++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java
@@ -596,7 +596,6 @@ public class WifiPickerTrackerTest {
config.networkId = networkId;
config.allowedKeyManagement = new BitSet();
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SUITE_B_192);
-
when(config.isPasspoint()).thenReturn(true);
when(config.getKey()).thenReturn(passpointConfig.getUniqueId());
when(mMockWifiManager.getPrivilegedConfiguredNetworks())
@@ -617,6 +616,51 @@ public class WifiPickerTrackerTest {
assertThat(wifiPickerTracker.getConnectedWifiEntry().getTitle()).isEqualTo(friendlyName);
}
+ @Test
+ public void testGetConnectedEntry_passpointWithoutScans_returnsPasspointEntry() {
+ final String fqdn = "fqdn";
+ final String friendlyName = "friendlyName";
+ final int networkId = 1;
+ // Create a passpoint configuration to match with the current network
+ 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));
+ // Create a wifi config to match the WifiInfo netId and unique id of the passpoint config
+ final WifiConfiguration config = Mockito.mock(WifiConfiguration.class);
+ config.SSID = "\"ssid\"";
+ config.networkId = networkId;
+ config.allowedKeyManagement = new BitSet();
+ config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SUITE_B_192);
+ when(config.isPasspoint()).thenReturn(true);
+ when(config.getKey()).thenReturn(passpointConfig.getUniqueId());
+ when(mMockWifiManager.getPrivilegedConfiguredNetworks())
+ .thenReturn(Collections.singletonList(config));
+ when(mMockWifiInfo.isPasspointAp()).thenReturn(true);
+ when(mMockWifiInfo.getNetworkId()).thenReturn(networkId);
+ when(mMockWifiInfo.getPasspointFqdn()).thenReturn(fqdn);
+ 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();
+
+ // Update with SCAN_RESULTS_AVAILABLE action while there are no scan results available yet.
+ mBroadcastReceiverCaptor.getValue().onReceive(mMockContext,
+ new Intent(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
+ mTestLooper.dispatchAll();
+
+ verify(mMockCallback, atLeastOnce()).onWifiEntriesChanged();
+ assertThat(wifiPickerTracker.getConnectedWifiEntry()).isNotNull();
+ assertThat(wifiPickerTracker.getConnectedWifiEntry().getTitle()).isEqualTo(friendlyName);
+ }
+
/**
* Tests that SCAN_RESULTS_AVAILABLE_ACTION calls WifiManager#getMatchingOsuProviders()
*/