diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-08-14 00:51:56 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-08-14 00:51:56 +0000 |
commit | ae0ff85e697a2919fc743d91fc8bf7b25e1c3be8 (patch) | |
tree | 071d2e65414e924a2b415555f72c1b01fad16aa0 | |
parent | 4976b67589de4033211b4495b1e1c5274cf03474 (diff) | |
parent | 96dd54c7507f9a5b94dd91719e83f5059e0c8c7d (diff) |
Merge "[WifiTrackerLib] Don't remove connected passpoint entry with no scans" into rvc-qpr-dev
-rw-r--r-- | libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java | 3 | ||||
-rw-r--r-- | libs/WifiTrackerLib/tests/src/com/android/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() */ |