summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorQuang Luong <qal@google.com>2020-02-27 23:54:26 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-02-27 23:54:26 +0000
commitbd3711e12e6d02667058f6552477412bb71a01af (patch)
tree27aa76a081d43a57544731d8af6b6fd4c48a067a /libs
parentca5676a2c42c46684b577cdff04fa64d5aa942ae (diff)
parent270e37c94bb67b338b3adbf49e6eb2c6ab493464 (diff)
Merge changes I8761aee5,Id8cdc487 into rvc-dev
* changes: [WifiTrackerLib] Fix Passpoint entry scan updates [WifiTrackerLib] Allow OSU provisioning from wifi picker
Diffstat (limited to 'libs')
-rw-r--r--libs/WifiTrackerLib/res/values/strings.xml18
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java116
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java6
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java42
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/SavedNetworkTracker.java13
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java50
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java39
7 files changed, 246 insertions, 38 deletions
diff --git a/libs/WifiTrackerLib/res/values/strings.xml b/libs/WifiTrackerLib/res/values/strings.xml
index 8758183da..1b49b299a 100644
--- a/libs/WifiTrackerLib/res/values/strings.xml
+++ b/libs/WifiTrackerLib/res/values/strings.xml
@@ -144,4 +144,22 @@
<!-- Passpoint summary for an expired passpoint [CHAR LIMIT=40] -->
<string name="wifi_passpoint_expired">Expired</string>
+
+ <!-- Status message of OSU Provider network when not connected. [CHAR LIMIT=NONE] -->
+ <string name="tap_to_sign_up">Tap to sign up</string>
+
+ <!-- Status message of OSU Provider upon initiating provisioning flow [CHAR LIMIT=NONE] -->
+ <string name="osu_opening_provider">Opening <xliff:g id="passpointProvider" example="Passpoint Provider">%1$s</xliff:g></string>
+
+ <!-- Status message of OSU Provider when connection fails [CHAR LIMIT=NONE] -->
+ <string name="osu_connect_failed">Couldn\u2019t connect</string>
+
+ <!-- Status message of OSU Provider after user completes provisioning flow [CHAR LIMIT=NONE] -->
+ <string name="osu_completing_sign_up">Completing sign-up\u2026</string>
+
+ <!-- Status message of OSU Provider when sign up could not be completed [CHAR LIMIT=NONE] -->
+ <string name="osu_sign_up_failed">Couldn\u2019t complete sign-up. Tap to try again.</string>
+
+ <!-- Status message of OSU Provider on completing provisioning. [CHAR LIMIT=NONE] -->
+ <string name="osu_sign_up_complete">Sign-up complete. Connecting\u2026</string>
</resources>
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java
index 244dd7949..97467d559 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java
@@ -19,7 +19,9 @@ package com.android.wifitrackerlib;
import static androidx.core.util.Preconditions.checkNotNull;
import static com.android.wifitrackerlib.Utils.getBestScanResultByLevel;
+import static com.android.wifitrackerlib.WifiEntry.ConnectCallback.CONNECT_STATUS_FAILURE_UNKNOWN;
+import android.annotation.MainThread;
import android.content.Context;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
@@ -27,14 +29,20 @@ import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.hotspot2.OsuProvider;
+import android.net.wifi.hotspot2.PasspointConfiguration;
+import android.net.wifi.hotspot2.ProvisioningCallback;
import android.os.Handler;
+import android.text.TextUtils;
+import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
/**
* WifiEntry representation of an Online Sign-up entry, uniquely identified by FQDN.
@@ -45,9 +53,9 @@ class OsuWifiEntry extends WifiEntry {
@NonNull private final List<ScanResult> mCurrentScanResults = new ArrayList<>();
@NonNull private final String mKey;
- @NonNull private String mFriendlyName;
@NonNull private final Context mContext;
@NonNull private OsuProvider mOsuProvider;
+ private String mOsuStatusString;
private int mLevel = WIFI_LEVEL_UNREACHABLE;
@@ -84,8 +92,9 @@ class OsuWifiEntry extends WifiEntry {
@Override
public String getSummary(boolean concise) {
- // TODO(b/70983952): Fill this method in
- return "Osu (Placeholder Text)"; // Placeholder string
+ // TODO(b/70983952): Add verbose summary
+ return mOsuStatusString != null
+ ? mOsuStatusString : mContext.getString(R.string.tap_to_sign_up);
}
@Override
@@ -139,7 +148,9 @@ class OsuWifiEntry extends WifiEntry {
@Override
public void connect(@Nullable ConnectCallback callback) {
- // TODO(b/70983952): Fill this method in.
+ mConnectCallback = callback;
+ mWifiManager.startSubscriptionProvisioning(mOsuProvider, mContext.getMainExecutor(),
+ new OsuWifiEntryProvisioningCallback());
}
// Exiting from the OSU flow should disconnect from the network.
@@ -283,8 +294,8 @@ class OsuWifiEntry extends WifiEntry {
@Override
protected boolean connectionInfoMatches(@NonNull WifiInfo wifiInfo,
@NonNull NetworkInfo networkInfo) {
- // TODO(b/70983952): Fill this method in.
- return false;
+ return wifiInfo.isOsuAp() && TextUtils.equals(
+ wifiInfo.getPasspointProviderFriendlyName(), mOsuProvider.getFriendlyName());
}
@Override
@@ -292,4 +303,97 @@ class OsuWifiEntry extends WifiEntry {
// TODO(b/70983952): Fill this method in.
return "";
}
+
+ OsuProvider getOsuProvider() {
+ return mOsuProvider;
+ }
+
+ class OsuWifiEntryProvisioningCallback extends ProvisioningCallback {
+ @Override
+ @MainThread public void onProvisioningFailure(int status) {
+ if (TextUtils.equals(
+ mOsuStatusString, mContext.getString(R.string.osu_completing_sign_up))) {
+ mOsuStatusString = mContext.getString(R.string.osu_sign_up_failed);
+ } else {
+ mOsuStatusString = mContext.getString(R.string.osu_connect_failed);
+ }
+ if (mConnectCallback != null) {
+ mConnectCallback.onConnectResult(CONNECT_STATUS_FAILURE_UNKNOWN);
+ }
+ notifyOnUpdated();
+ }
+
+ @Override
+ @MainThread public void onProvisioningStatus(int status) {
+ String newStatusString = null;
+ switch (status) {
+ case OSU_STATUS_AP_CONNECTING:
+ case OSU_STATUS_AP_CONNECTED:
+ case OSU_STATUS_SERVER_CONNECTING:
+ case OSU_STATUS_SERVER_VALIDATED:
+ case OSU_STATUS_SERVER_CONNECTED:
+ case OSU_STATUS_INIT_SOAP_EXCHANGE:
+ case OSU_STATUS_WAITING_FOR_REDIRECT_RESPONSE:
+ newStatusString = String.format(mContext.getString(
+ R.string.osu_opening_provider),
+ mOsuProvider.getFriendlyName());
+ break;
+ case OSU_STATUS_REDIRECT_RESPONSE_RECEIVED:
+ case OSU_STATUS_SECOND_SOAP_EXCHANGE:
+ case OSU_STATUS_THIRD_SOAP_EXCHANGE:
+ case OSU_STATUS_RETRIEVING_TRUST_ROOT_CERTS:
+ newStatusString = mContext.getString(R.string.osu_completing_sign_up);
+ break;
+ }
+ boolean updated = !TextUtils.equals(mOsuStatusString, newStatusString);
+ mOsuStatusString = newStatusString;
+ if (updated) {
+ notifyOnUpdated();
+ }
+ }
+
+ @Override
+ @MainThread public void onProvisioningComplete() {
+ mOsuStatusString = mContext.getString(R.string.osu_sign_up_complete);
+ notifyOnUpdated();
+
+ PasspointConfiguration passpointConfig = mWifiManager
+ .getMatchingPasspointConfigsForOsuProviders(Collections.singleton(mOsuProvider))
+ .get(mOsuProvider);
+ if (passpointConfig == null) {
+ // Failed to find the config we just provisioned
+ if (mConnectCallback != null) {
+ mConnectCallback.onConnectResult(CONNECT_STATUS_FAILURE_UNKNOWN);
+ }
+ return;
+ }
+ String uniqueId = passpointConfig.getUniqueId();
+ for (Pair<WifiConfiguration, Map<Integer, List<ScanResult>>> pairing :
+ mWifiManager.getAllMatchingWifiConfigs(mWifiManager.getScanResults())) {
+ WifiConfiguration config = pairing.first;
+ if (TextUtils.equals(config.getKey(), uniqueId)) {
+ List<ScanResult> homeScans =
+ pairing.second.get(WifiManager.PASSPOINT_HOME_NETWORK);
+ List<ScanResult> roamingScans =
+ pairing.second.get(WifiManager.PASSPOINT_ROAMING_NETWORK);
+ ScanResult bestScan;
+ if (homeScans != null && !homeScans.isEmpty()) {
+ bestScan = getBestScanResultByLevel(homeScans);
+ } else if (roamingScans != null && !roamingScans.isEmpty()) {
+ bestScan = getBestScanResultByLevel(roamingScans);
+ } else {
+ break;
+ }
+ config.SSID = "\"" + bestScan.SSID + "\"";
+ mWifiManager.connect(config, null /* ActionListener */);
+ return;
+ }
+ }
+
+ // Failed to find the network we provisioned for
+ if (mConnectCallback != null) {
+ mConnectCallback.onConnectResult(CONNECT_STATUS_FAILURE_UNKNOWN);
+ }
+ }
+ }
}
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 3e2419faf..4cb790024 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
@@ -340,33 +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 {
+ mIsRoaming = false;
mWifiConfig = wifiConfig;
- mSecurity = getSecurityTypeFromWifiConfiguration(wifiConfig);
-
- if (homeScanResults == null) {
- homeScanResults = new ArrayList<>();
+ mCurrentHomeScanResults.clear();
+ mCurrentRoamingScanResults.clear();
+ if (homeScanResults != null) {
+ mCurrentHomeScanResults.addAll(homeScanResults);
}
- if (roamingScanResults == null) {
- roamingScanResults = new ArrayList<>();
+ if (roamingScanResults != null) {
+ mCurrentRoamingScanResults.addAll(roamingScanResults);
}
-
- ScanResult bestScanResult;
- if (homeScanResults.isEmpty() && !roamingScanResults.isEmpty()) {
- mIsRoaming = true;
- bestScanResult = getBestScanResultByLevel(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 {
- mIsRoaming = false;
- bestScanResult = getBestScanResultByLevel(homeScanResults);
- }
-
- if (bestScanResult == null) {
mLevel = WIFI_LEVEL_UNREACHABLE;
- } else {
- mLevel = mWifiManager.calculateSignalLevel(bestScanResult.level);
}
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 21d3f2c27..7cd83f4a7 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
@@ -61,6 +61,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,8 +219,11 @@ public class WifiPickerTracker extends BaseWifiTracker {
updateStandardWifiEntryConfigs(mWifiManager.getConfiguredNetworks());
}
updatePasspointWifiEntryConfigs(mWifiManager.getPasspointConfigurations());
- updateStandardWifiEntryScans(mScanResultUpdater.getScanResults());
- updatePasspointWifiEntryScans(mScanResultUpdater.getScanResults());
+ // Update scans since config changes may result in different entries being shown.
+ final List<ScanResult> scanResults = mScanResultUpdater.getScanResults();
+ updateStandardWifiEntryScans(scanResults);
+ updatePasspointWifiEntryScans(scanResults);
+ updateOsuWifiEntryScans(scanResults);
notifyOnNumSavedNetworksChanged();
notifyOnNumSavedSubscriptionsChanged();
updateWifiEntries();
@@ -272,6 +277,13 @@ public class WifiPickerTracker extends BaseWifiTracker {
|| connectedState == CONNECTED_STATE_CONNECTING;
}).findAny().orElse(null /* other */);
}
+ if (mConnectedWifiEntry == null) {
+ mConnectedWifiEntry = mOsuWifiEntryCache.values().stream().filter(entry -> {
+ final @WifiEntry.ConnectedState int connectedState = entry.getConnectedState();
+ return connectedState == CONNECTED_STATE_CONNECTED
+ || connectedState == CONNECTED_STATE_CONNECTING;
+ }).findAny().orElse(null /* other */);
+ }
Collections.sort(mWifiEntries);
if (isVerboseLoggingEnabled()) {
Log.v(TAG, "Connected WifiEntry: " + mConnectedWifiEntry);
@@ -325,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) {
@@ -334,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;
@@ -351,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
@@ -360,18 +375,26 @@ public class WifiPickerTracker extends BaseWifiTracker {
Map<OsuProvider, List<ScanResult>> osuProviderToScans =
mWifiManager.getMatchingOsuProviders(scanResults);
- for (OsuProvider osuProvider : osuProviderToScans.keySet()) {
- final String key = osuProviderToOsuWifiEntryKey(osuProvider);
- if (!mOsuWifiEntryCache.containsKey(key)) {
- mOsuWifiEntryCache.put(key, new OsuWifiEntry(mContext,
- mMainHandler, osuProvider, mWifiManager, false /* forSavedNetworksPage */));
- }
- mOsuWifiEntryCache.get(key).updateScanResultInfo(osuProviderToScans.get(osuProvider));
+ Set<OsuProvider> alreadyProvisioned =
+ mWifiManager.getMatchingPasspointConfigsForOsuProviders(osuProviderToScans.keySet())
+ .keySet();
+ // Update each OsuWifiEntry with new scans (or empty scans).
+ for (OsuWifiEntry entry : mOsuWifiEntryCache.values()) {
+ entry.updateScanResultInfo(osuProviderToScans.remove(entry.getOsuProvider()));
}
- // Remove entries that are now unreachable
+ // Create a new entry for each OsuProvider not already matched to an OsuWifiEntry
+ for (OsuProvider provider : osuProviderToScans.keySet()) {
+ OsuWifiEntry newEntry = new OsuWifiEntry(mContext, mMainHandler, provider, mWifiManager,
+ false /* forSavedNetworksPage */);
+ newEntry.updateScanResultInfo(osuProviderToScans.get(provider));
+ mOsuWifiEntryCache.put(osuProviderToOsuWifiEntryKey(provider), newEntry);
+ }
+
+ // Remove entries that are now unreachable or already provisioned
mOsuWifiEntryCache.entrySet()
- .removeIf(entry -> entry.getValue().getLevel() == WIFI_LEVEL_UNREACHABLE);
+ .removeIf(entry -> entry.getValue().getLevel() == WIFI_LEVEL_UNREACHABLE
+ || alreadyProvisioned.contains(entry.getValue().getOsuProvider()));
}
/**
@@ -487,6 +510,9 @@ public class WifiPickerTracker extends BaseWifiTracker {
for (WifiEntry entry : mPasspointWifiEntryCache.values()) {
entry.updateConnectionInfo(wifiInfo, networkInfo);
}
+ for (WifiEntry entry : mOsuWifiEntryCache.values()) {
+ entry.updateConnectionInfo(wifiInfo, networkInfo);
+ }
}
/**
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";