Merge "Added special constructors for Passpoint and OSU AccessPoints"
This commit is contained in:
@@ -57,6 +57,7 @@ import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
import com.android.settingslib.R;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
@@ -132,6 +133,12 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
/** The underlying set of scan results comprising this AccessPoint. */
|
||||
private final ArraySet<ScanResult> mScanResults = new ArraySet<>();
|
||||
|
||||
/**
|
||||
* Extra set of unused scan results corresponding to this AccessPoint for verbose logging
|
||||
* purposes, such as a set of Passpoint roaming scan results when home scans are available.
|
||||
*/
|
||||
private final ArraySet<ScanResult> mExtraScanResults = new ArraySet<>();
|
||||
|
||||
/**
|
||||
* Map of BSSIDs to scored networks for individual bssids.
|
||||
*
|
||||
@@ -216,6 +223,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
*/
|
||||
private String mFqdn;
|
||||
private String mProviderFriendlyName;
|
||||
private boolean mIsRoaming = false;
|
||||
|
||||
private boolean mIsCarrierAp = false;
|
||||
|
||||
@@ -289,15 +297,12 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
|
||||
// Calculate required fields
|
||||
updateKey();
|
||||
updateRssi();
|
||||
updateBestRssiInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AccessPoint with only a WifiConfiguration. This is used for the saved networks
|
||||
* page.
|
||||
*
|
||||
* Passpoint Credential AccessPoints should be created with this.
|
||||
* Make sure to call setScanResults after constructing with this.
|
||||
*/
|
||||
public AccessPoint(Context context, WifiConfiguration config) {
|
||||
mContext = context;
|
||||
@@ -315,39 +320,33 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize an AccessPoint object for a Passpoint OSU Provider.
|
||||
* Make sure to call setScanResults after constructing with this.
|
||||
* Initialize an AccessPoint object for a Passpoint network.
|
||||
*/
|
||||
public AccessPoint(Context context, OsuProvider provider) {
|
||||
public AccessPoint(@NonNull Context context, @NonNull WifiConfiguration config,
|
||||
@Nullable Collection<ScanResult> homeScans,
|
||||
@Nullable Collection<ScanResult> roamingScans) {
|
||||
mContext = context;
|
||||
networkId = config.networkId;
|
||||
mConfig = config;
|
||||
setScanResultsPasspoint(homeScans, roamingScans);
|
||||
updateKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize an AccessPoint object for a Passpoint OSU Provider.
|
||||
*/
|
||||
public AccessPoint(@NonNull Context context, @NonNull OsuProvider provider,
|
||||
@NonNull Collection<ScanResult> results) {
|
||||
mContext = context;
|
||||
mOsuProvider = provider;
|
||||
ssid = provider.getFriendlyName();
|
||||
setScanResults(results);
|
||||
updateKey();
|
||||
}
|
||||
|
||||
AccessPoint(Context context, Collection<ScanResult> results) {
|
||||
mContext = context;
|
||||
|
||||
if (results.isEmpty()) {
|
||||
throw new IllegalArgumentException("Cannot construct with an empty ScanResult list");
|
||||
}
|
||||
mScanResults.addAll(results);
|
||||
|
||||
// Information derived from scan results
|
||||
ScanResult firstResult = results.iterator().next();
|
||||
ssid = firstResult.SSID;
|
||||
bssid = firstResult.BSSID;
|
||||
security = getSecurity(firstResult);
|
||||
if (security == SECURITY_PSK) {
|
||||
pskType = getPskType(firstResult);
|
||||
}
|
||||
setScanResults(results);
|
||||
updateKey();
|
||||
updateRssi();
|
||||
|
||||
// Passpoint Info
|
||||
mIsCarrierAp = firstResult.isCarrierAp;
|
||||
mCarrierApEapType = firstResult.carrierApEapType;
|
||||
mCarrierName = firstResult.carrierName;
|
||||
}
|
||||
|
||||
@VisibleForTesting void loadConfig(WifiConfiguration config) {
|
||||
@@ -468,7 +467,8 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
|
||||
if (isVerboseLoggingEnabled()) {
|
||||
builder.append(",rssi=").append(mRssi);
|
||||
builder.append(",scan cache size=").append(mScanResults.size());
|
||||
builder.append(",scan cache size=").append(mScanResults.size()
|
||||
+ mExtraScanResults.size());
|
||||
}
|
||||
|
||||
return builder.append(')').toString();
|
||||
@@ -703,14 +703,19 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
*
|
||||
* <p>Callers should not modify this set.
|
||||
*/
|
||||
public Set<ScanResult> getScanResults() { return mScanResults; }
|
||||
public Set<ScanResult> getScanResults() {
|
||||
Set<ScanResult> allScans = new ArraySet<>();
|
||||
allScans.addAll(mScanResults);
|
||||
allScans.addAll(mExtraScanResults);
|
||||
return allScans;
|
||||
}
|
||||
|
||||
public Map<String, TimestampedScoredNetwork> getScoredNetworkCache() {
|
||||
return mScoredNetworkCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates {@link #mRssi}.
|
||||
* Updates {@link #mRssi} and sets scan result information to that of the best RSSI scan result.
|
||||
*
|
||||
* <p>If the given connection is active, the existing value of {@link #mRssi} will be returned.
|
||||
* If the given AccessPoint is not active, a value will be calculated from previous scan
|
||||
@@ -718,22 +723,41 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
* value. If the access point is not connected and there are no scan results, the rssi will be
|
||||
* set to {@link #UNREACHABLE_RSSI}.
|
||||
*/
|
||||
private void updateRssi() {
|
||||
private void updateBestRssiInfo() {
|
||||
if (this.isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int rssi = UNREACHABLE_RSSI;
|
||||
ScanResult bestResult = null;
|
||||
int bestRssi = UNREACHABLE_RSSI;
|
||||
for (ScanResult result : mScanResults) {
|
||||
if (result.level > rssi) {
|
||||
rssi = result.level;
|
||||
if (result.level > bestRssi) {
|
||||
bestRssi = result.level;
|
||||
bestResult = result;
|
||||
}
|
||||
}
|
||||
|
||||
if (rssi != UNREACHABLE_RSSI && mRssi != UNREACHABLE_RSSI) {
|
||||
mRssi = (mRssi + rssi) / 2; // half-life previous value
|
||||
// Set the rssi to the average of the current rssi and the previous rssi.
|
||||
if (bestRssi != UNREACHABLE_RSSI && mRssi != UNREACHABLE_RSSI) {
|
||||
mRssi = (mRssi + bestRssi) / 2;
|
||||
} else {
|
||||
mRssi = rssi;
|
||||
mRssi = bestRssi;
|
||||
}
|
||||
|
||||
if (bestResult != null) {
|
||||
ssid = bestResult.SSID;
|
||||
bssid = bestResult.BSSID;
|
||||
security = getSecurity(bestResult);
|
||||
if (security == SECURITY_PSK) {
|
||||
pskType = getPskType(bestResult);
|
||||
}
|
||||
mIsCarrierAp = bestResult.isCarrierAp;
|
||||
mCarrierApEapType = bestResult.carrierApEapType;
|
||||
mCarrierName = bestResult.carrierName;
|
||||
}
|
||||
// Update the config SSID of a Passpoint network to that of the best RSSI
|
||||
if (isPasspoint()) {
|
||||
mConfig.SSID = convertToQuotedString(ssid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -897,18 +921,12 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
summary.append(mContext.getString(R.string.tap_to_sign_up));
|
||||
}
|
||||
} else if (isActive()) {
|
||||
if (isPasspoint()) {
|
||||
// This is the active connection on passpoint
|
||||
summary.append(getSummary(mContext, /* ssid */ null, getDetailedState(),
|
||||
/* isEphemeral */ false,
|
||||
/* suggestionOrSpecifierPackageName */ null));
|
||||
} else if (mConfig != null && getDetailedState() == DetailedState.CONNECTED
|
||||
if (mConfig != null && getDetailedState() == DetailedState.CONNECTED
|
||||
&& mIsCarrierAp) {
|
||||
// This is the active connection on a carrier AP
|
||||
summary.append(String.format(mContext.getString(R.string.connected_via_carrier),
|
||||
mCarrierName));
|
||||
} else {
|
||||
// This is the active connection on non-passpoint network
|
||||
summary.append(getSummary(mContext, /* ssid */ null, getDetailedState(),
|
||||
mInfo != null && mInfo.isEphemeral(),
|
||||
mInfo != null ? mInfo.getNetworkSuggestionOrSpecifierPackageName() : null));
|
||||
@@ -1107,7 +1125,8 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
if (mConfig != null) savedState.putParcelable(KEY_CONFIG, mConfig);
|
||||
savedState.putParcelable(KEY_WIFIINFO, mInfo);
|
||||
savedState.putParcelableArray(KEY_SCANRESULTS,
|
||||
mScanResults.toArray(new Parcelable[mScanResults.size()]));
|
||||
mScanResults.toArray(new Parcelable[mScanResults.size()
|
||||
+ mExtraScanResults.size()]));
|
||||
savedState.putParcelableArrayList(KEY_SCOREDNETWORKCACHE,
|
||||
new ArrayList<>(mScoredNetworkCache.values()));
|
||||
if (mNetworkInfo != null) {
|
||||
@@ -1129,24 +1148,27 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets {@link #mScanResults} to the given collection.
|
||||
* Sets {@link #mScanResults} to the given collection and updates info based on the best RSSI
|
||||
* scan result.
|
||||
*
|
||||
* @param scanResults a collection of scan results to add to the internal set
|
||||
* @throws IllegalArgumentException if any of the given ScanResults did not belong to this AP
|
||||
*/
|
||||
void setScanResults(Collection<ScanResult> scanResults) {
|
||||
if (CollectionUtils.isEmpty(scanResults)) {
|
||||
Log.d(TAG, "Cannot set scan results to empty list");
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate scan results are for current AP only by matching SSID/BSSID
|
||||
// Passpoint networks are not bound to a specific SSID/BSSID, so skip this for passpoint.
|
||||
if (!isPasspoint() && !isOsuProvider()) {
|
||||
String key = getKey();
|
||||
if (mKey != null && !isPasspoint() && !isOsuProvider()) {
|
||||
for (ScanResult result : scanResults) {
|
||||
String scanResultKey = AccessPoint.getKey(result);
|
||||
if (!mKey.equals(scanResultKey)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
if (mKey != null && !mKey.equals(scanResultKey)) {
|
||||
Log.d(TAG, String.format(
|
||||
"ScanResult %s\nkey of %s did not match current AP key %s",
|
||||
result, scanResultKey, key));
|
||||
result, scanResultKey, mKey));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1154,7 +1176,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
int oldLevel = getLevel();
|
||||
mScanResults.clear();
|
||||
mScanResults.addAll(scanResults);
|
||||
updateRssi();
|
||||
updateBestRssiInfo();
|
||||
int newLevel = getLevel();
|
||||
|
||||
// If newLevel is 0, there will be no displayed Preference since the AP is unreachable
|
||||
@@ -1174,20 +1196,26 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
mAccessPointListener.onAccessPointChanged(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!scanResults.isEmpty()) {
|
||||
ScanResult result = scanResults.iterator().next();
|
||||
|
||||
// This flag only comes from scans, is not easily saved in config
|
||||
if (security == SECURITY_PSK) {
|
||||
pskType = getPskType(result);
|
||||
/**
|
||||
* Sets the internal scan result cache to the list of home scans.
|
||||
* If there are no home scans, then the roaming scan list is used, and the AccessPoint is
|
||||
* marked as roaming.
|
||||
*/
|
||||
void setScanResultsPasspoint(
|
||||
@Nullable Collection<ScanResult> homeScans,
|
||||
@Nullable Collection<ScanResult> roamingScans) {
|
||||
mExtraScanResults.clear();
|
||||
if (!CollectionUtils.isEmpty(homeScans)) {
|
||||
if (!CollectionUtils.isEmpty(roamingScans)) {
|
||||
mExtraScanResults.addAll(roamingScans);
|
||||
}
|
||||
|
||||
// The carrier info in the ScanResult is set by the platform based on the SSID and will
|
||||
// always be the same for all matching scan results.
|
||||
mIsCarrierAp = result.isCarrierAp;
|
||||
mCarrierApEapType = result.carrierApEapType;
|
||||
mCarrierName = result.carrierName;
|
||||
mIsRoaming = false;
|
||||
setScanResults(homeScans);
|
||||
} else if (!CollectionUtils.isEmpty(roamingScans)) {
|
||||
mIsRoaming = true;
|
||||
setScanResults(roamingScans);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1204,7 +1232,6 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
*/
|
||||
public boolean update(
|
||||
@Nullable WifiConfiguration config, WifiInfo info, NetworkInfo networkInfo) {
|
||||
|
||||
boolean updated = false;
|
||||
final int oldLevel = getLevel();
|
||||
if (info != null && isInfoForThisAccessPoint(config, info)) {
|
||||
@@ -1538,7 +1565,8 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
*
|
||||
* All methods are invoked on the Main Thread
|
||||
*/
|
||||
private class AccessPointProvisioningCallback extends ProvisioningCallback {
|
||||
@VisibleForTesting
|
||||
class AccessPointProvisioningCallback extends ProvisioningCallback {
|
||||
@Override
|
||||
@MainThread public void onProvisioningFailure(int status) {
|
||||
if (TextUtils.equals(mOsuStatus, mContext.getString(R.string.osu_completing_sign_up))) {
|
||||
|
||||
@@ -53,7 +53,6 @@ import androidx.annotation.GuardedBy;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
import com.android.settingslib.R;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
@@ -646,30 +645,14 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
|
||||
Map<Integer, List<ScanResult>>> pairing : passpointConfigsAndScans) {
|
||||
WifiConfiguration config = pairing.first;
|
||||
if (seenFQDNs.add(config.FQDN)) {
|
||||
List<ScanResult> apScanResults = new ArrayList<>();
|
||||
|
||||
List<ScanResult> homeScans =
|
||||
pairing.second.get(WifiManager.PASSPOINT_HOME_NETWORK);
|
||||
List<ScanResult> roamingScans =
|
||||
pairing.second.get(WifiManager.PASSPOINT_ROAMING_NETWORK);
|
||||
|
||||
// TODO(b/118705403): Differentiate home network vs roaming network for summary info
|
||||
if (!CollectionUtils.isEmpty(homeScans)) {
|
||||
apScanResults.addAll(homeScans);
|
||||
} else if (!CollectionUtils.isEmpty(roamingScans)) {
|
||||
apScanResults.addAll(roamingScans);
|
||||
}
|
||||
|
||||
int bestRssi = Integer.MIN_VALUE;
|
||||
for (ScanResult result : apScanResults) {
|
||||
if (result.level >= bestRssi) {
|
||||
bestRssi = result.level;
|
||||
config.SSID = AccessPoint.convertToQuotedString(result.SSID);
|
||||
}
|
||||
}
|
||||
|
||||
AccessPoint accessPoint =
|
||||
getCachedOrCreatePasspoint(apScanResults, accessPointCache, config);
|
||||
getCachedOrCreatePasspoint(config, homeScans, roamingScans,
|
||||
accessPointCache);
|
||||
accessPoints.add(accessPoint);
|
||||
}
|
||||
}
|
||||
@@ -688,8 +671,8 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
|
||||
for (OsuProvider provider : providersAndScans.keySet()) {
|
||||
if (!alreadyProvisioned.contains(provider)) {
|
||||
AccessPoint accessPointOsu =
|
||||
getCachedOrCreateOsu(providersAndScans.get(provider),
|
||||
accessPointCache, provider);
|
||||
getCachedOrCreateOsu(provider, providersAndScans.get(provider),
|
||||
accessPointCache);
|
||||
accessPoints.add(accessPointOsu);
|
||||
}
|
||||
}
|
||||
@@ -709,26 +692,29 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
|
||||
}
|
||||
|
||||
private AccessPoint getCachedOrCreatePasspoint(
|
||||
List<ScanResult> scanResults,
|
||||
List<AccessPoint> cache,
|
||||
WifiConfiguration config) {
|
||||
WifiConfiguration config,
|
||||
List<ScanResult> homeScans,
|
||||
List<ScanResult> roamingScans,
|
||||
List<AccessPoint> cache) {
|
||||
AccessPoint accessPoint = getCachedByKey(cache, AccessPoint.getKey(config));
|
||||
if (accessPoint == null) {
|
||||
accessPoint = new AccessPoint(mContext, config);
|
||||
accessPoint = new AccessPoint(mContext, config, homeScans, roamingScans);
|
||||
} else {
|
||||
accessPoint.setScanResultsPasspoint(homeScans, roamingScans);
|
||||
}
|
||||
accessPoint.setScanResults(scanResults);
|
||||
return accessPoint;
|
||||
}
|
||||
|
||||
private AccessPoint getCachedOrCreateOsu(
|
||||
OsuProvider provider,
|
||||
List<ScanResult> scanResults,
|
||||
List<AccessPoint> cache,
|
||||
OsuProvider provider) {
|
||||
List<AccessPoint> cache) {
|
||||
AccessPoint accessPoint = getCachedByKey(cache, AccessPoint.getKey(provider));
|
||||
if (accessPoint == null) {
|
||||
accessPoint = new AccessPoint(mContext, provider);
|
||||
accessPoint = new AccessPoint(mContext, provider, scanResults);
|
||||
} else {
|
||||
accessPoint.setScanResults(scanResults);
|
||||
}
|
||||
accessPoint.setScanResults(scanResults);
|
||||
return accessPoint;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,13 +43,16 @@ import android.net.wifi.WifiEnterpriseConfig;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiNetworkScoreCache;
|
||||
import android.net.wifi.WifiSsid;
|
||||
import android.net.wifi.hotspot2.OsuProvider;
|
||||
import android.net.wifi.hotspot2.PasspointConfiguration;
|
||||
import android.net.wifi.hotspot2.ProvisioningCallback;
|
||||
import android.net.wifi.hotspot2.pps.HomeSp;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.os.SystemClock;
|
||||
import android.text.SpannableString;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
@@ -68,6 +71,9 @@ import org.mockito.MockitoAnnotations;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
@SmallTest
|
||||
@@ -75,8 +81,11 @@ import java.util.concurrent.CountDownLatch;
|
||||
public class AccessPointTest {
|
||||
|
||||
private static final String TEST_SSID = "\"test_ssid\"";
|
||||
private static final String ROAMING_SSID = "\"roaming_ssid\"";
|
||||
private static final String OSU_FRIENDLY_NAME = "osu_friendly_name";
|
||||
|
||||
private static final ArrayList<ScanResult> SCAN_RESULTS = buildScanResultCache();
|
||||
private ArrayList<ScanResult> mScanResults;
|
||||
private ArrayList<ScanResult> mRoamingScans;
|
||||
|
||||
private static final RssiCurve FAST_BADGE_CURVE =
|
||||
new RssiCurve(-150, 10, new byte[]{Speed.FAST});
|
||||
@@ -88,10 +97,11 @@ public class AccessPointTest {
|
||||
private WifiInfo mWifiInfo;
|
||||
@Mock private RssiCurve mockBadgeCurve;
|
||||
@Mock private WifiNetworkScoreCache mockWifiNetworkScoreCache;
|
||||
public static final int NETWORK_ID = 123;
|
||||
public static final int DEFAULT_RSSI = -55;
|
||||
@Mock private AccessPoint.AccessPointListener mMockAccessPointListener;
|
||||
private static final int NETWORK_ID = 123;
|
||||
private static final int DEFAULT_RSSI = -55;
|
||||
|
||||
private static ScanResult createScanResult(String ssid, String bssid, int rssi) {
|
||||
private ScanResult createScanResult(String ssid, String bssid, int rssi) {
|
||||
ScanResult scanResult = new ScanResult();
|
||||
scanResult.SSID = ssid;
|
||||
scanResult.level = rssi;
|
||||
@@ -101,6 +111,12 @@ public class AccessPointTest {
|
||||
return scanResult;
|
||||
}
|
||||
|
||||
private OsuProvider createOsuProvider() {
|
||||
Map<String, String> friendlyNames = new HashMap<>();
|
||||
friendlyNames.put("en", OSU_FRIENDLY_NAME);
|
||||
return new OsuProvider(null, friendlyNames, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@@ -108,6 +124,8 @@ public class AccessPointTest {
|
||||
mWifiInfo = new WifiInfo();
|
||||
mWifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(TEST_SSID));
|
||||
mWifiInfo.setBSSID(TEST_BSSID);
|
||||
mScanResults = buildScanResultCache(TEST_SSID);
|
||||
mRoamingScans = buildScanResultCache(ROAMING_SSID);
|
||||
WifiTracker.sVerboseLogging = false;
|
||||
}
|
||||
|
||||
@@ -573,14 +591,14 @@ public class AccessPointTest {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelableArray(
|
||||
AccessPoint.KEY_SCANRESULTS,
|
||||
SCAN_RESULTS.toArray(new Parcelable[SCAN_RESULTS.size()]));
|
||||
mScanResults.toArray(new Parcelable[mScanResults.size()]));
|
||||
return new AccessPoint(mContext, bundle);
|
||||
}
|
||||
|
||||
private static ArrayList<ScanResult> buildScanResultCache() {
|
||||
private ArrayList<ScanResult> buildScanResultCache(String ssid) {
|
||||
ArrayList<ScanResult> scanResults = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ScanResult scanResult = createScanResult(TEST_SSID, "bssid-" + i, i);
|
||||
ScanResult scanResult = createScanResult(ssid, "bssid-" + i, i);
|
||||
scanResults.add(scanResult);
|
||||
}
|
||||
return scanResults;
|
||||
@@ -975,12 +993,12 @@ public class AccessPointTest {
|
||||
int speed1 = Speed.MODERATE;
|
||||
RssiCurve badgeCurve1 = mock(RssiCurve.class);
|
||||
when(badgeCurve1.lookupScore(anyInt())).thenReturn((byte) speed1);
|
||||
when(mockWifiNetworkScoreCache.getScoredNetwork(SCAN_RESULTS.get(0)))
|
||||
when(mockWifiNetworkScoreCache.getScoredNetwork(mScanResults.get(0)))
|
||||
.thenReturn(buildScoredNetworkWithGivenBadgeCurve(badgeCurve1));
|
||||
int speed2 = Speed.VERY_FAST;
|
||||
RssiCurve badgeCurve2 = mock(RssiCurve.class);
|
||||
when(badgeCurve2.lookupScore(anyInt())).thenReturn((byte) speed2);
|
||||
when(mockWifiNetworkScoreCache.getScoredNetwork(SCAN_RESULTS.get(1)))
|
||||
when(mockWifiNetworkScoreCache.getScoredNetwork(mScanResults.get(1)))
|
||||
.thenReturn(buildScoredNetworkWithGivenBadgeCurve(badgeCurve2));
|
||||
|
||||
int expectedSpeed = (speed1 + speed2) / 2;
|
||||
@@ -998,12 +1016,12 @@ public class AccessPointTest {
|
||||
int speed1 = Speed.VERY_FAST;
|
||||
RssiCurve badgeCurve1 = mock(RssiCurve.class);
|
||||
when(badgeCurve1.lookupScore(anyInt())).thenReturn((byte) speed1);
|
||||
when(mockWifiNetworkScoreCache.getScoredNetwork(SCAN_RESULTS.get(0)))
|
||||
when(mockWifiNetworkScoreCache.getScoredNetwork(mScanResults.get(0)))
|
||||
.thenReturn(buildScoredNetworkWithGivenBadgeCurve(badgeCurve1));
|
||||
int speed2 = Speed.NONE;
|
||||
RssiCurve badgeCurve2 = mock(RssiCurve.class);
|
||||
when(badgeCurve2.lookupScore(anyInt())).thenReturn((byte) speed2);
|
||||
when(mockWifiNetworkScoreCache.getScoredNetwork(SCAN_RESULTS.get(1)))
|
||||
when(mockWifiNetworkScoreCache.getScoredNetwork(mScanResults.get(1)))
|
||||
.thenReturn(buildScoredNetworkWithGivenBadgeCurve(badgeCurve2));
|
||||
|
||||
ap.update(
|
||||
@@ -1123,7 +1141,7 @@ public class AccessPointTest {
|
||||
.setActive(true)
|
||||
.setScoredNetworkCache(
|
||||
new ArrayList(Arrays.asList(recentScore)))
|
||||
.setScanResults(SCAN_RESULTS)
|
||||
.setScanResults(mScanResults)
|
||||
.build();
|
||||
|
||||
when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class)))
|
||||
@@ -1151,7 +1169,7 @@ public class AccessPointTest {
|
||||
.setActive(true)
|
||||
.setScoredNetworkCache(
|
||||
new ArrayList(Arrays.asList(recentScore)))
|
||||
.setScanResults(SCAN_RESULTS)
|
||||
.setScanResults(mScanResults)
|
||||
.build();
|
||||
|
||||
int newSpeed = Speed.MODERATE;
|
||||
@@ -1196,7 +1214,7 @@ public class AccessPointTest {
|
||||
AccessPoint ap = new TestAccessPointBuilder(mContext)
|
||||
.setSsid(TEST_SSID)
|
||||
.setBssid(TEST_BSSID)
|
||||
.setScanResults(SCAN_RESULTS)
|
||||
.setScanResults(mScanResults)
|
||||
.build();
|
||||
|
||||
assertThat(ap.update(null, mWifiInfo, null)).isFalse();
|
||||
@@ -1217,4 +1235,172 @@ public class AccessPointTest {
|
||||
|
||||
assertThat(passpointAp.update(null, mWifiInfo, null)).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that an AccessPoint's getKey() is consistent with the overloaded static getKey().
|
||||
*/
|
||||
@Test
|
||||
public void testGetKey_matchesKeysCorrectly() {
|
||||
AccessPoint ap = new AccessPoint(mContext, mScanResults);
|
||||
assertThat(ap.getKey()).isEqualTo(AccessPoint.getKey(mScanResults.get(0)));
|
||||
|
||||
WifiConfiguration spyConfig = spy(new WifiConfiguration());
|
||||
when(spyConfig.isPasspoint()).thenReturn(true);
|
||||
spyConfig.FQDN = "fqdn";
|
||||
AccessPoint passpointAp = new AccessPoint(mContext, spyConfig, mScanResults, null);
|
||||
assertThat(passpointAp.getKey()).isEqualTo(AccessPoint.getKey(spyConfig));
|
||||
|
||||
OsuProvider provider = createOsuProvider();
|
||||
AccessPoint osuAp = new AccessPoint(mContext, provider, mScanResults);
|
||||
assertThat(osuAp.getKey()).isEqualTo(AccessPoint.getKey(provider));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the Passpoint AccessPoint constructor creates AccessPoints whose isPasspoint()
|
||||
* returns true.
|
||||
*/
|
||||
@Test
|
||||
public void testPasspointAccessPointConstructor_createdAccessPointIsPasspoint() {
|
||||
WifiConfiguration spyConfig = spy(new WifiConfiguration());
|
||||
when(spyConfig.isPasspoint()).thenReturn(true);
|
||||
AccessPoint passpointAccessPoint = new AccessPoint(mContext, spyConfig,
|
||||
mScanResults, mRoamingScans);
|
||||
|
||||
assertThat(passpointAccessPoint.isPasspoint()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that Passpoint AccessPoints set their config's SSID to the home scans', and to the
|
||||
* roaming scans' if no home scans are available.
|
||||
*/
|
||||
@Test
|
||||
public void testSetScanResultsPasspoint_differentiatesHomeAndRoaming() {
|
||||
WifiConfiguration spyConfig = spy(new WifiConfiguration());
|
||||
when(spyConfig.isPasspoint()).thenReturn(true);
|
||||
AccessPoint passpointAccessPoint = new AccessPoint(mContext, spyConfig,
|
||||
mScanResults, mRoamingScans);
|
||||
assertThat(AccessPoint.removeDoubleQuotes(spyConfig.SSID)).isEqualTo(TEST_SSID);
|
||||
|
||||
passpointAccessPoint.setScanResultsPasspoint(null, mRoamingScans);
|
||||
assertThat(AccessPoint.removeDoubleQuotes(spyConfig.SSID)).isEqualTo(ROAMING_SSID);
|
||||
|
||||
passpointAccessPoint.setScanResultsPasspoint(mScanResults, null);
|
||||
assertThat(AccessPoint.removeDoubleQuotes(spyConfig.SSID)).isEqualTo(TEST_SSID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that getScanResults returns both home and roaming scans.
|
||||
*/
|
||||
@Test
|
||||
public void testGetScanResults_showsHomeAndRoamingScans() {
|
||||
WifiConfiguration spyConfig = spy(new WifiConfiguration());
|
||||
when(spyConfig.isPasspoint()).thenReturn(true);
|
||||
AccessPoint passpointAccessPoint = new AccessPoint(mContext, spyConfig,
|
||||
mScanResults, mRoamingScans);
|
||||
Set<ScanResult> fullSet = new ArraySet<>();
|
||||
fullSet.addAll(mScanResults);
|
||||
fullSet.addAll(mRoamingScans);
|
||||
assertThat(passpointAccessPoint.getScanResults()).isEqualTo(fullSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the Passpoint AccessPoint takes the ssid of the strongest scan result.
|
||||
*/
|
||||
@Test
|
||||
public void testPasspointAccessPoint_setsBestSsid() {
|
||||
WifiConfiguration spyConfig = spy(new WifiConfiguration());
|
||||
when(spyConfig.isPasspoint()).thenReturn(true);
|
||||
|
||||
String badSsid = "badSsid";
|
||||
String goodSsid = "goodSsid";
|
||||
String bestSsid = "bestSsid";
|
||||
ScanResult badScanResult = createScanResult(badSsid, TEST_BSSID, -100);
|
||||
ScanResult goodScanResult = createScanResult(goodSsid, TEST_BSSID, -10);
|
||||
ScanResult bestScanResult = createScanResult(bestSsid, TEST_BSSID, -1);
|
||||
|
||||
AccessPoint passpointAccessPoint = new AccessPoint(mContext, spyConfig,
|
||||
Arrays.asList(badScanResult, goodScanResult), null);
|
||||
assertThat(passpointAccessPoint.getConfig().SSID)
|
||||
.isEqualTo(AccessPoint.convertToQuotedString(goodSsid));
|
||||
passpointAccessPoint.setScanResultsPasspoint(
|
||||
Arrays.asList(badScanResult, goodScanResult, bestScanResult), null);
|
||||
assertThat(passpointAccessPoint.getConfig().SSID)
|
||||
.isEqualTo(AccessPoint.convertToQuotedString(bestSsid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the OSU AccessPoint constructor creates AccessPoints whose isOsuProvider()
|
||||
* returns true.
|
||||
*/
|
||||
@Test
|
||||
public void testOsuAccessPointConstructor_createdAccessPointIsOsuProvider() {
|
||||
AccessPoint osuAccessPoint = new AccessPoint(mContext, createOsuProvider(),
|
||||
mScanResults);
|
||||
|
||||
assertThat(osuAccessPoint.isOsuProvider()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the summary of an OSU entry only shows the tap_to_sign_up string.
|
||||
*/
|
||||
@Test
|
||||
public void testOsuAccessPointSummary_showsTapToSignUp() {
|
||||
AccessPoint osuAccessPoint = new AccessPoint(mContext, createOsuProvider(),
|
||||
mScanResults);
|
||||
|
||||
assertThat(osuAccessPoint.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.tap_to_sign_up));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOsuAccessPointSummary_showsProvisioningUpdates() {
|
||||
AccessPoint osuAccessPoint = new AccessPoint(mContext, createOsuProvider(),
|
||||
mScanResults);
|
||||
|
||||
osuAccessPoint.setListener(mMockAccessPointListener);
|
||||
|
||||
AccessPoint.AccessPointProvisioningCallback provisioningCallback =
|
||||
osuAccessPoint.new AccessPointProvisioningCallback();
|
||||
|
||||
int[] openingProviderStatuses = {
|
||||
ProvisioningCallback.OSU_STATUS_AP_CONNECTING,
|
||||
ProvisioningCallback.OSU_STATUS_AP_CONNECTED,
|
||||
ProvisioningCallback.OSU_STATUS_SERVER_CONNECTING,
|
||||
ProvisioningCallback.OSU_STATUS_SERVER_VALIDATED,
|
||||
ProvisioningCallback.OSU_STATUS_SERVER_CONNECTED,
|
||||
ProvisioningCallback.OSU_STATUS_INIT_SOAP_EXCHANGE,
|
||||
ProvisioningCallback.OSU_STATUS_WAITING_FOR_REDIRECT_RESPONSE
|
||||
};
|
||||
int[] completingSignUpStatuses = {
|
||||
ProvisioningCallback.OSU_STATUS_REDIRECT_RESPONSE_RECEIVED,
|
||||
ProvisioningCallback.OSU_STATUS_SECOND_SOAP_EXCHANGE,
|
||||
ProvisioningCallback.OSU_STATUS_THIRD_SOAP_EXCHANGE,
|
||||
ProvisioningCallback.OSU_STATUS_RETRIEVING_TRUST_ROOT_CERTS,
|
||||
};
|
||||
|
||||
for (int status : openingProviderStatuses) {
|
||||
provisioningCallback.onProvisioningStatus(status);
|
||||
assertThat(osuAccessPoint.getSummary())
|
||||
.isEqualTo(String.format(mContext.getString(R.string.osu_opening_provider),
|
||||
OSU_FRIENDLY_NAME));
|
||||
}
|
||||
|
||||
provisioningCallback.onProvisioningFailure(0);
|
||||
assertThat(osuAccessPoint.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.osu_connect_failed));
|
||||
|
||||
for (int status : completingSignUpStatuses) {
|
||||
provisioningCallback.onProvisioningStatus(status);
|
||||
assertThat(osuAccessPoint.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.osu_completing_sign_up));
|
||||
}
|
||||
|
||||
provisioningCallback.onProvisioningFailure(0);
|
||||
assertThat(osuAccessPoint.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.osu_sign_up_failed));
|
||||
|
||||
provisioningCallback.onProvisioningComplete();
|
||||
assertThat(osuAccessPoint.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.osu_sign_up_complete));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1155,8 +1155,7 @@ public class WifiTrackerTest {
|
||||
providersAndScans, cachedAccessPoints);
|
||||
|
||||
// Verify second update AP is the same object as the first update AP
|
||||
assertTrue(osuAccessPointsFirstUpdate.get(0)
|
||||
== osuAccessPointsSecondUpdate.get(0));
|
||||
assertThat(osuAccessPointsFirstUpdate.get(0)).isSameAs(osuAccessPointsSecondUpdate.get(0));
|
||||
// Verify second update AP has the average of the first and second update RSSIs
|
||||
assertThat(osuAccessPointsSecondUpdate.get(0).getRssi())
|
||||
.isEqualTo((prevRssi + newRssi) / 2);
|
||||
|
||||
Reference in New Issue
Block a user