From 96dd54c7507f9a5b94dd91719e83f5059e0c8c7d Mon Sep 17 00:00:00 2001 From: Quang Luong Date: Wed, 12 Aug 2020 17:03:32 -0700 Subject: [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 --- .../android/wifitrackerlib/WifiPickerTracker.java | 3 +- .../wifitrackerlib/WifiPickerTrackerTest.java | 46 +++++++++++++++++++++- 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() */ -- cgit v1.2.3