summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/hotspot2/ANQPRequestManager.java13
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointManager.java60
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java8
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointNetworkScore.java10
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPRequestManagerTest.java54
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java99
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java12
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkScoreTest.java8
8 files changed, 150 insertions, 114 deletions
diff --git a/service/java/com/android/server/wifi/hotspot2/ANQPRequestManager.java b/service/java/com/android/server/wifi/hotspot2/ANQPRequestManager.java
index fd756c3a2..dfdf4ad16 100644
--- a/service/java/com/android/server/wifi/hotspot2/ANQPRequestManager.java
+++ b/service/java/com/android/server/wifi/hotspot2/ANQPRequestManager.java
@@ -20,7 +20,6 @@ import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.wifi.Clock;
-import com.android.server.wifi.ScanDetail;
import com.android.server.wifi.hotspot2.anqp.Constants;
import java.util.ArrayList;
@@ -43,7 +42,7 @@ public class ANQPRequestManager {
/**
* List of pending ANQP request associated with an AP (BSSID).
*/
- private final Map<Long, ScanDetail> mPendingQueries;
+ private final Map<Long, ANQPNetworkKey> mPendingQueries;
/**
* List of hold off time information associated with APs specified by their BSSID.
@@ -109,14 +108,14 @@ public class ANQPRequestManager {
* supported Hotspot 2.0 release version).
*
* @param bssid The BSSID of the AP
- * @param scanDetail The ScanDetail associated with this request
+ * @param anqpNetworkKey The unique network key associated with this request
* @param rcOIs Flag indicating the inclusion of roaming consortium OIs. When set to true,
* Roaming Consortium ANQP element will be requested
* @param hsReleaseR2 Flag indicating the support of Hotspot 2.0 Release 2. When set to true,
* the Release 2 ANQP elements {@link #R2_ANQP_BASE_SET} will be requested
* @return true if a request was sent successfully
*/
- public boolean requestANQPElements(long bssid, ScanDetail scanDetail, boolean rcOIs,
+ public boolean requestANQPElements(long bssid, ANQPNetworkKey anqpNetworkKey, boolean rcOIs,
boolean hsReleaseR2) {
// Check if we are allow to send the request now.
if (!canSendRequestNow(bssid)) {
@@ -132,7 +131,7 @@ public class ANQPRequestManager {
// the given AP.
updateHoldOffInfo(bssid);
- mPendingQueries.put(bssid, scanDetail);
+ mPendingQueries.put(bssid, anqpNetworkKey);
return true;
}
@@ -141,9 +140,9 @@ public class ANQPRequestManager {
*
* @param bssid The BSSID of the AP
* @param success Flag indicating the result of the query
- * @return {@link ScanDetail} associated with the completed request
+ * @return {@link ANQPNetworkKey} associated with the completed request
*/
- public ScanDetail onRequestCompleted(long bssid, boolean success) {
+ public ANQPNetworkKey onRequestCompleted(long bssid, boolean success) {
if (success) {
// Query succeeded. No need to hold off request to the given AP.
mHoldOffInfo.remove(bssid);
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
index ff8b50f77..f88c9d5bc 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
@@ -29,6 +29,7 @@ import static android.net.wifi.WifiManager.EXTRA_URL;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.IconInfo;
+import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.hotspot2.PasspointConfiguration;
@@ -39,13 +40,13 @@ import android.util.Pair;
import com.android.server.wifi.Clock;
import com.android.server.wifi.SIMAccessor;
-import com.android.server.wifi.ScanDetail;
import com.android.server.wifi.WifiConfigManager;
import com.android.server.wifi.WifiConfigStore;
import com.android.server.wifi.WifiKeyStore;
import com.android.server.wifi.WifiNative;
import com.android.server.wifi.hotspot2.anqp.ANQPElement;
import com.android.server.wifi.hotspot2.anqp.Constants;
+import com.android.server.wifi.util.InformationElementUtil;
import java.util.ArrayList;
import java.util.HashMap;
@@ -103,23 +104,16 @@ public class PasspointManager {
public void onANQPResponse(long bssid,
Map<Constants.ANQPElementType, ANQPElement> anqpElements) {
// Notify request manager for the completion of a request.
- ScanDetail scanDetail =
+ ANQPNetworkKey anqpKey =
mAnqpRequestManager.onRequestCompleted(bssid, anqpElements != null);
- if (anqpElements == null || scanDetail == null) {
+ if (anqpElements == null || anqpKey == null) {
// Query failed or the request wasn't originated from us (not tracked by the
// request manager). Nothing to be done.
return;
}
// Add new entry to the cache.
- NetworkDetail networkDetail = scanDetail.getNetworkDetail();
- ANQPNetworkKey anqpKey = ANQPNetworkKey.buildKey(networkDetail.getSSID(),
- networkDetail.getBSSID(), networkDetail.getHESSID(),
- networkDetail.getAnqpDomainID());
mAnqpCache.addEntry(anqpKey, anqpElements);
-
- // Update ANQP elements in the ScanDetail.
- scanDetail.propagateANQPInfo(anqpElements);
}
@Override
@@ -286,26 +280,32 @@ public class PasspointManager {
*
* An empty list will returned in the case when no match is found.
*
- * @param scanDetail The detail information of the AP
+ * @param scanResult The scan result associated with the AP
* @return List of {@link PasspointProvider}
*/
- public List<Pair<PasspointProvider, PasspointMatch>> matchProvider(ScanDetail scanDetail) {
+ public List<Pair<PasspointProvider, PasspointMatch>> matchProvider(ScanResult scanResult) {
// Nothing to be done if no Passpoint provider is installed.
if (mProviders.isEmpty()) {
return new ArrayList<Pair<PasspointProvider, PasspointMatch>>();
}
+ // Retrieve the relevant information elements, mainly Roaming Consortium IE and Hotspot 2.0
+ // Vendor Specific IE.
+ InformationElementUtil.RoamingConsortium roamingConsortium =
+ InformationElementUtil.getRoamingConsortiumIE(scanResult.informationElements);
+ InformationElementUtil.Vsa vsa = InformationElementUtil.getHS2VendorSpecificIE(
+ scanResult.informationElements);
+
// Lookup ANQP data in the cache.
- NetworkDetail networkDetail = scanDetail.getNetworkDetail();
- ANQPNetworkKey anqpKey = ANQPNetworkKey.buildKey(networkDetail.getSSID(),
- networkDetail.getBSSID(), networkDetail.getHESSID(),
- networkDetail.getAnqpDomainID());
+ long bssid = Utils.parseMac(scanResult.BSSID);
+ ANQPNetworkKey anqpKey = ANQPNetworkKey.buildKey(scanResult.SSID, bssid, scanResult.hessid,
+ vsa.anqpDomainID);
ANQPData anqpEntry = mAnqpCache.getEntry(anqpKey);
if (anqpEntry == null) {
- mAnqpRequestManager.requestANQPElements(networkDetail.getBSSID(), scanDetail,
- networkDetail.getAnqpOICount() > 0,
- networkDetail.getHSRelease() == NetworkDetail.HSRelease.R2);
+ mAnqpRequestManager.requestANQPElements(bssid, anqpKey,
+ roamingConsortium.anqpOICount > 0,
+ vsa.hsRelease == NetworkDetail.HSRelease.R2);
return new ArrayList<Pair<PasspointProvider, PasspointMatch>>();
}
@@ -383,6 +383,28 @@ public class PasspointManager {
}
/**
+ * Lookup the ANQP elements associated with the given AP from the cache. An empty map
+ * will be returned if no match found in the cache.
+ *
+ * @param scanResult The scan result associated with the AP
+ * @return Map of ANQP elements
+ */
+ public Map<Constants.ANQPElementType, ANQPElement> getANQPElements(ScanResult scanResult) {
+ // Retrieve the Hotspot 2.0 Vendor Specific IE.
+ InformationElementUtil.Vsa vsa =
+ InformationElementUtil.getHS2VendorSpecificIE(scanResult.informationElements);
+
+ // Lookup ANQP data in the cache.
+ long bssid = Utils.parseMac(scanResult.BSSID);
+ ANQPData anqpEntry = mAnqpCache.getEntry(ANQPNetworkKey.buildKey(
+ scanResult.SSID, bssid, scanResult.hessid, vsa.anqpDomainID));
+ if (anqpEntry != null) {
+ return anqpEntry.getElements();
+ }
+ return new HashMap<Constants.ANQPElementType, ANQPElement>();
+ }
+
+ /**
* Add a legacy Passpoint configuration represented by a {@link WifiConfiguration}.
*
* @param wifiConfig {@link WifiConfiguration} representation of the Passpoint configuration
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java
index f08b5de32..a1fbcffce 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java
@@ -62,6 +62,9 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva
WifiConfiguration currentNetwork, String currentBssid,
boolean connected, boolean untrustedNetworkAllowed,
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks) {
+ // Sweep the ANQP cache to remove any expired ANQP entries.
+ mPasspointManager.sweepCache();
+
// Go through each ScanDetail and find the best provider for each ScanDetail.
List<Pair<ScanDetail, Pair<PasspointProvider, PasspointMatch>>> providerList =
new ArrayList<>();
@@ -72,7 +75,7 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva
}
List<Pair<PasspointProvider, PasspointMatch>> matchedProviders =
- mPasspointManager.matchProvider(scanDetail);
+ mPasspointManager.matchProvider(scanDetail.getScanResult());
// Find the best provider for this ScanDetail.
Pair<PasspointProvider, PasspointMatch> bestProvider =
@@ -181,7 +184,8 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva
boolean isActiveNetwork = TextUtils.equals(currentNetworkSsid,
ScanResultUtil.createQuotedSSID(scanDetail.getSSID()));
int score = PasspointNetworkScore.calculateScore(match == PasspointMatch.HomeProvider,
- scanDetail, isActiveNetwork);
+ scanDetail, mPasspointManager.getANQPElements(scanDetail.getScanResult()),
+ isActiveNetwork);
if (score > bestScore) {
bestScanDetail = scanDetail;
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkScore.java b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkScore.java
index 2dc3789f5..03f2e4c2d 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkScore.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkScore.java
@@ -145,7 +145,7 @@ public class PasspointNetworkScore {
* @return integer score
*/
public static int calculateScore(boolean isHomeProvider, ScanDetail scanDetail,
- boolean isActiveNetwork) {
+ Map<ANQPElementType, ANQPElement> anqpElements, boolean isActiveNetwork) {
NetworkDetail networkDetail = scanDetail.getNetworkDetail();
int score = 0;
if (isHomeProvider) {
@@ -158,9 +158,9 @@ public class PasspointNetworkScore {
// Adjust score based on the network type.
score += NETWORK_TYPE_SCORES.get(networkDetail.getAnt());
- Map<ANQPElementType, ANQPElement> anqp = networkDetail.getANQPElements();
- if (anqp != null) {
- HSWanMetricsElement wm = (HSWanMetricsElement) anqp.get(ANQPElementType.HSWANMetrics);
+ if (anqpElements != null) {
+ HSWanMetricsElement wm =
+ (HSWanMetricsElement) anqpElements.get(ANQPElementType.HSWANMetrics);
if (wm != null) {
if (wm.getStatus() != HSWanMetricsElement.LINK_STATUS_UP || wm.isCapped()) {
score -= WAN_PORT_DOWN_OR_CAPPED_PENALTY;
@@ -168,7 +168,7 @@ public class PasspointNetworkScore {
}
IPAddressTypeAvailabilityElement ipa = (IPAddressTypeAvailabilityElement)
- anqp.get(ANQPElementType.ANQPIPAddrAvailability);
+ anqpElements.get(ANQPElementType.ANQPIPAddrAvailability);
if (ipa != null) {
Integer v4Score = IPV4_SCORES.get(ipa.getV4Availability());
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPRequestManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPRequestManagerTest.java
index 08b37deb9..022d22dae 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPRequestManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPRequestManagerTest.java
@@ -16,11 +16,11 @@
package com.android.server.wifi.hotspot2;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.anyObject;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
@@ -30,7 +30,6 @@ import static org.mockito.MockitoAnnotations.initMocks;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.server.wifi.Clock;
-import com.android.server.wifi.ScanDetail;
import com.android.server.wifi.hotspot2.anqp.Constants;
import org.junit.Before;
@@ -46,7 +45,8 @@ import java.util.List;
@SmallTest
public class ANQPRequestManagerTest {
private static final long TEST_BSSID = 0x123456L;
- private static final ScanDetail TEST_SCAN_DETAIL = mock(ScanDetail.class);
+ private static final ANQPNetworkKey TEST_ANQP_KEY =
+ new ANQPNetworkKey("TestSSID", TEST_BSSID, 0, 0);
private static final List<Constants.ANQPElementType> R1_ANQP_WITHOUT_RC = Arrays.asList(
Constants.ANQPElementType.ANQPVenueName,
@@ -107,7 +107,7 @@ public class ANQPRequestManagerTest {
@Test
public void requestR1ANQPElementsWithoutRC() throws Exception {
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(true);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
}
/**
@@ -120,7 +120,7 @@ public class ANQPRequestManagerTest {
@Test
public void requestR1ANQPElementsWithRC() throws Exception {
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITH_RC)).thenReturn(true);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, true, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, true, false));
}
/**
@@ -133,7 +133,7 @@ public class ANQPRequestManagerTest {
@Test
public void requestR1R2ANQPElementsWithoutRC() throws Exception {
when(mHandler.requestANQP(TEST_BSSID, R1R2_ANQP_WITHOUT_RC)).thenReturn(true);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, true));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, true));
}
/**
@@ -146,7 +146,7 @@ public class ANQPRequestManagerTest {
@Test
public void requestR1R2ANQPElementsWithRC() throws Exception {
when(mHandler.requestANQP(TEST_BSSID, R1R2_ANQP_WITH_RC)).thenReturn(true);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, true, true));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, true, true));
}
/**
@@ -161,13 +161,13 @@ public class ANQPRequestManagerTest {
long startTime = 0;
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(true);
when(mClock.getElapsedSinceBootMillis()).thenReturn(startTime);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
reset(mHandler);
// Attempt another request will fail while one is still pending and hold off time is not up
// yet.
when(mClock.getElapsedSinceBootMillis()).thenReturn(startTime + 1);
- assertFalse(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertFalse(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
verify(mHandler, never()).requestANQP(anyLong(), anyObject());
reset(mHandler);
@@ -175,7 +175,7 @@ public class ANQPRequestManagerTest {
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(true);
when(mClock.getElapsedSinceBootMillis())
.thenReturn(startTime + ANQPRequestManager.BASE_HOLDOFF_TIME_MILLISECONDS);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
}
/**
@@ -190,13 +190,13 @@ public class ANQPRequestManagerTest {
long startTime = 0;
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(false);
when(mClock.getElapsedSinceBootMillis()).thenReturn(startTime);
- assertFalse(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertFalse(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
reset(mHandler);
// Verify that new request is not being held off after previous send failure.
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(true);
when(mClock.getElapsedSinceBootMillis()).thenReturn(startTime);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
}
/**
@@ -211,15 +211,16 @@ public class ANQPRequestManagerTest {
long startTime = 0;
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(true);
when(mClock.getElapsedSinceBootMillis()).thenReturn(startTime);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
reset(mHandler);
- // Request completed with success.
- mManager.onRequestCompleted(TEST_BSSID, true);
+ // Request completed with success. Verify that the key associated with the request
+ // is returned.
+ assertEquals(TEST_ANQP_KEY, mManager.onRequestCompleted(TEST_BSSID, true));
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(true);
when(mClock.getElapsedSinceBootMillis()).thenReturn(startTime + 1);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
}
/**
@@ -235,22 +236,23 @@ public class ANQPRequestManagerTest {
long startTime = 0;
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(true);
when(mClock.getElapsedSinceBootMillis()).thenReturn(startTime);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
reset(mHandler);
- // Request completed with failure.
- mManager.onRequestCompleted(TEST_BSSID, false);
+ // Request completed with failure. Verify that the key associated with the request
+ // is returned
+ assertEquals(TEST_ANQP_KEY, mManager.onRequestCompleted(TEST_BSSID, false));
// Attempt another request will fail since the hold off time is not up yet.
when(mClock.getElapsedSinceBootMillis()).thenReturn(startTime + 1);
- assertFalse(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertFalse(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
verify(mHandler, never()).requestANQP(anyLong(), anyObject());
// Attempt another request will succeed after the hold off time is up.
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(true);
when(mClock.getElapsedSinceBootMillis())
.thenReturn(startTime + ANQPRequestManager.BASE_HOLDOFF_TIME_MILLISECONDS);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
}
/**
@@ -266,7 +268,7 @@ public class ANQPRequestManagerTest {
// Initial request.
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(true);
when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTime);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
reset(mHandler);
// Sending the request with the hold off time based on the current hold off count.
@@ -276,14 +278,14 @@ public class ANQPRequestManagerTest {
// Request will fail before the hold off time is up.
when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTime);
- assertFalse(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertFalse(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
verify(mHandler, never()).requestANQP(anyLong(), anyObject());
// Request will succeed when the hold off time is up.
currentTime += 1;
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(true);
when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTime);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
reset(mHandler);
}
@@ -292,13 +294,13 @@ public class ANQPRequestManagerTest {
* (1 << ANQPRequestManager.MAX_HOLDOFF_COUNT) - 1);
when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTime);
- assertFalse(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertFalse(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
verify(mHandler, never()).requestANQP(anyLong(), anyObject());
currentTime += 1;
when(mHandler.requestANQP(TEST_BSSID, R1_ANQP_WITHOUT_RC)).thenReturn(true);
when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTime);
- assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_SCAN_DETAIL, false, false));
+ assertTrue(mManager.requestANQPElements(TEST_BSSID, TEST_ANQP_KEY, false, false));
reset(mHandler);
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
index e424b4dbe..a86d961ba 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
@@ -45,6 +45,7 @@ import android.content.Context;
import android.content.Intent;
import android.net.wifi.EAPConstants;
import android.net.wifi.IconInfo;
+import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.hotspot2.PasspointConfiguration;
@@ -59,7 +60,6 @@ import com.android.server.wifi.Clock;
import com.android.server.wifi.FakeKeys;
import com.android.server.wifi.IMSIParameter;
import com.android.server.wifi.SIMAccessor;
-import com.android.server.wifi.ScanDetail;
import com.android.server.wifi.WifiConfigManager;
import com.android.server.wifi.WifiConfigStore;
import com.android.server.wifi.WifiKeyStore;
@@ -94,9 +94,12 @@ public class PasspointManagerTest {
private static final IMSIParameter TEST_IMSI_PARAM = IMSIParameter.build(TEST_IMSI);
private static final String TEST_SSID = "TestSSID";
- private static final long TEST_BSSID = 0x1234L;
+ private static final long TEST_BSSID = 0x112233445566L;
+ private static final String TEST_BSSID_STRING = "11:22:33:44:55:66";
private static final long TEST_HESSID = 0x5678L;
- private static final int TEST_ANQP_DOMAIN_ID = 1;
+ private static final int TEST_ANQP_DOMAIN_ID = 0;
+ private static final ANQPNetworkKey TEST_ANQP_KEY = ANQPNetworkKey.buildKey(
+ TEST_SSID, TEST_BSSID, TEST_HESSID, TEST_ANQP_DOMAIN_ID);
@Mock Context mContext;
@Mock WifiNative mWifiNative;
@@ -239,20 +242,16 @@ public class PasspointManagerTest {
}
/**
- * Helper function for creating a mock ScanDetail.
+ * Helper function for creating a ScanResult for testing.
*
- * @return {@link ScanDetail}
+ * @return {@link ScanResult}
*/
- private ScanDetail createMockScanDetail() {
- NetworkDetail networkDetail = mock(NetworkDetail.class);
- when(networkDetail.getSSID()).thenReturn(TEST_SSID);
- when(networkDetail.getBSSID()).thenReturn(TEST_BSSID);
- when(networkDetail.getHESSID()).thenReturn(TEST_HESSID);
- when(networkDetail.getAnqpDomainID()).thenReturn(TEST_ANQP_DOMAIN_ID);
-
- ScanDetail scanDetail = mock(ScanDetail.class);
- when(scanDetail.getNetworkDetail()).thenReturn(networkDetail);
- return scanDetail;
+ private ScanResult createTestScanResult() {
+ ScanResult scanResult = new ScanResult();
+ scanResult.SSID = TEST_SSID;
+ scanResult.BSSID = TEST_BSSID_STRING;
+ scanResult.hessid = TEST_HESSID;
+ return scanResult;
}
/**
@@ -267,13 +266,9 @@ public class PasspointManagerTest {
anqpElementMap.put(ANQPElementType.ANQPDomName,
new DomainNameElement(Arrays.asList(new String[] {"test.com"})));
- ScanDetail scanDetail = createMockScanDetail();
- ANQPNetworkKey anqpKey = ANQPNetworkKey.buildKey(TEST_SSID, TEST_BSSID, TEST_HESSID,
- TEST_ANQP_DOMAIN_ID);
- when(mAnqpRequestManager.onRequestCompleted(TEST_BSSID, true)).thenReturn(scanDetail);
+ when(mAnqpRequestManager.onRequestCompleted(TEST_BSSID, true)).thenReturn(TEST_ANQP_KEY);
mCallbacks.onANQPResponse(TEST_BSSID, anqpElementMap);
- verify(mAnqpCache).addEntry(anqpKey, anqpElementMap);
- verify(scanDetail).propagateANQPInfo(anqpElementMap);
+ verify(mAnqpCache).addEntry(TEST_ANQP_KEY, anqpElementMap);
}
/**
@@ -300,11 +295,7 @@ public class PasspointManagerTest {
*/
@Test
public void anqpResponseFailure() throws Exception {
- ANQPNetworkKey anqpKey = ANQPNetworkKey.buildKey(TEST_SSID, TEST_BSSID, TEST_HESSID,
- TEST_ANQP_DOMAIN_ID);
-
- ScanDetail scanDetail = createMockScanDetail();
- when(mAnqpRequestManager.onRequestCompleted(TEST_BSSID, false)).thenReturn(scanDetail);
+ when(mAnqpRequestManager.onRequestCompleted(TEST_BSSID, false)).thenReturn(TEST_ANQP_KEY);
mCallbacks.onANQPResponse(TEST_BSSID, null);
verify(mAnqpCache, never()).addEntry(any(ANQPNetworkKey.class), anyMap());
@@ -568,7 +559,7 @@ public class PasspointManagerTest {
@Test
public void matchProviderWithNoProvidersInstalled() throws Exception {
List<Pair<PasspointProvider, PasspointMatch>> result =
- mManager.matchProvider(createMockScanDetail());
+ mManager.matchProvider(createTestScanResult());
assertTrue(result.isEmpty());
}
@@ -581,13 +572,11 @@ public class PasspointManagerTest {
public void matchProviderWithAnqpCacheMissed() throws Exception {
addTestProvider();
- ANQPNetworkKey anqpKey = ANQPNetworkKey.buildKey(TEST_SSID, TEST_BSSID, TEST_HESSID,
- TEST_ANQP_DOMAIN_ID);
- when(mAnqpCache.getEntry(anqpKey)).thenReturn(null);
+ when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(null);
List<Pair<PasspointProvider, PasspointMatch>> result =
- mManager.matchProvider(createMockScanDetail());
+ mManager.matchProvider(createTestScanResult());
// Verify that a request for ANQP elements is initiated.
- verify(mAnqpRequestManager).requestANQPElements(eq(TEST_BSSID), any(ScanDetail.class),
+ verify(mAnqpRequestManager).requestANQPElements(eq(TEST_BSSID), any(ANQPNetworkKey.class),
anyBoolean(), anyBoolean());
assertTrue(result.isEmpty());
}
@@ -602,13 +591,11 @@ public class PasspointManagerTest {
public void matchProviderAsHomeProvider() throws Exception {
PasspointProvider provider = addTestProvider();
ANQPData entry = new ANQPData(mClock, null);
- ANQPNetworkKey anqpKey = ANQPNetworkKey.buildKey(TEST_SSID, TEST_BSSID, TEST_HESSID,
- TEST_ANQP_DOMAIN_ID);
- when(mAnqpCache.getEntry(anqpKey)).thenReturn(entry);
+ when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry);
when(provider.match(anyMap())).thenReturn(PasspointMatch.HomeProvider);
List<Pair<PasspointProvider, PasspointMatch>> result =
- mManager.matchProvider(createMockScanDetail());
+ mManager.matchProvider(createTestScanResult());
assertEquals(1, result.size());
assertEquals(PasspointMatch.HomeProvider, result.get(0).second);
}
@@ -623,13 +610,11 @@ public class PasspointManagerTest {
public void matchProviderAsRoamingProvider() throws Exception {
PasspointProvider provider = addTestProvider();
ANQPData entry = new ANQPData(mClock, null);
- ANQPNetworkKey anqpKey = ANQPNetworkKey.buildKey(TEST_SSID, TEST_BSSID, TEST_HESSID,
- TEST_ANQP_DOMAIN_ID);
- when(mAnqpCache.getEntry(anqpKey)).thenReturn(entry);
+ when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry);
when(provider.match(anyMap())).thenReturn(PasspointMatch.RoamingProvider);
List<Pair<PasspointProvider, PasspointMatch>> result =
- mManager.matchProvider(createMockScanDetail());
+ mManager.matchProvider(createTestScanResult());
assertEquals(1, result.size());
assertEquals(PasspointMatch.RoamingProvider, result.get(0).second);
assertEquals(TEST_FQDN, provider.getConfig().getHomeSp().getFqdn());
@@ -644,13 +629,11 @@ public class PasspointManagerTest {
public void matchProviderWithNoMatch() throws Exception {
PasspointProvider provider = addTestProvider();
ANQPData entry = new ANQPData(mClock, null);
- ANQPNetworkKey anqpKey = ANQPNetworkKey.buildKey(TEST_SSID, TEST_BSSID, TEST_HESSID,
- TEST_ANQP_DOMAIN_ID);
- when(mAnqpCache.getEntry(anqpKey)).thenReturn(entry);
+ when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry);
when(provider.match(anyMap())).thenReturn(PasspointMatch.None);
List<Pair<PasspointProvider, PasspointMatch>> result =
- mManager.matchProvider(createMockScanDetail());
+ mManager.matchProvider(createTestScanResult());
assertEquals(0, result.size());
}
@@ -666,6 +649,34 @@ public class PasspointManagerTest {
}
/**
+ * Verify that an empty map will be returned if ANQP elements are not cached for the given AP.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void getANQPElementsWithNoMatchFound() throws Exception {
+ when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(null);
+ assertTrue(mManager.getANQPElements(createTestScanResult()).isEmpty());
+ }
+
+ /**
+ * Verify that an expected ANQP elements will be returned if ANQP elements are cached for the
+ * given AP.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void getANQPElementsWithMatchFound() throws Exception {
+ Map<ANQPElementType, ANQPElement> anqpElementMap = new HashMap<>();
+ anqpElementMap.put(ANQPElementType.ANQPDomName,
+ new DomainNameElement(Arrays.asList(new String[] {"test.com"})));
+ ANQPData entry = new ANQPData(mClock, anqpElementMap);
+
+ when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry);
+ assertEquals(anqpElementMap, mManager.getANQPElements(createTestScanResult()));
+ }
+
+ /**
* Verify that the provider list maintained by the PasspointManager after the list is updated
* in the data source.
*
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
index 616e2161a..05d9ea225 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
@@ -129,7 +129,7 @@ public class PasspointNetworkEvaluatorTest {
generateScanDetail(TEST_SSID1), generateScanDetail(TEST_SSID2)});
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
List<Pair<PasspointProvider, PasspointMatch>> matchedProviders = new ArrayList<>();
- when(mPasspointManager.matchProvider(any(ScanDetail.class))).thenReturn(matchedProviders);
+ when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(matchedProviders);
assertEquals(null, mEvaluator.evaluateNetworks(
scanDetails, null, null, false, false, connectableNetworks));
assertTrue(connectableNetworks.isEmpty());
@@ -154,7 +154,7 @@ public class PasspointNetworkEvaluatorTest {
scanDetails, null, null, false, false, connectableNetworks));
assertTrue(connectableNetworks.isEmpty());
// Verify that no provider matching is performed.
- verify(mPasspointManager, never()).matchProvider(any(ScanDetail.class));
+ verify(mPasspointManager, never()).matchProvider(any(ScanResult.class));
}
/**
@@ -181,7 +181,7 @@ public class PasspointNetworkEvaluatorTest {
// Return matchedProviders for the first ScanDetail (TEST_SSID1) and an empty list for
// for the second (TEST_SSID2);
- when(mPasspointManager.matchProvider(any(ScanDetail.class))).thenReturn(matchedProviders)
+ when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(matchedProviders)
.thenReturn(new ArrayList<Pair<PasspointProvider, PasspointMatch>>());
when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
.thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
@@ -224,7 +224,7 @@ public class PasspointNetworkEvaluatorTest {
// Return matchedProviders for the first ScanDetail (TEST_SSID1) and an empty list for
// for the second (TEST_SSID2);
- when(mPasspointManager.matchProvider(any(ScanDetail.class))).thenReturn(matchedProviders)
+ when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(matchedProviders)
.thenReturn(new ArrayList<Pair<PasspointProvider, PasspointMatch>>());
when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
.thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
@@ -271,7 +271,7 @@ public class PasspointNetworkEvaluatorTest {
// Return providerForScanDetail1 for the first ScanDetail (TEST_SSID1) and
// providerForScanDetail2 for the second (TEST_SSID2);
- when(mPasspointManager.matchProvider(any(ScanDetail.class)))
+ when(mPasspointManager.matchProvider(any(ScanResult.class)))
.thenReturn(providerForScanDetail1).thenReturn(providerForScanDetail2);
when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
.thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
@@ -318,7 +318,7 @@ public class PasspointNetworkEvaluatorTest {
// Returning the same matching provider for both ScanDetail.
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- when(mPasspointManager.matchProvider(any(ScanDetail.class)))
+ when(mPasspointManager.matchProvider(any(ScanResult.class)))
.thenReturn(matchedProviders).thenReturn(matchedProviders);
WifiConfiguration config = mEvaluator.evaluateNetworks(scanDetails, currentNetwork,
currentBssid, true, false, connectableNetworks);
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkScoreTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkScoreTest.java
index cca321233..10c50f5d3 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkScoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkScoreTest.java
@@ -309,11 +309,10 @@ public class PasspointNetworkScoreTest {
* @param rssiLevel RSSI level of the network
* @param internetAccess Flag indicating if the network provides Internet access
* @param networkType The type of the network
- * @param anqpElements The list of ANQP elements
* @return {@link ScanDetail}
*/
private static ScanDetail generateScanDetail(int rssiLevel, boolean internetAccess,
- NetworkDetail.Ant networkType, Map<ANQPElementType, ANQPElement> anqpElements) {
+ NetworkDetail.Ant networkType) {
// Setup ScanResult.
ScanResult scanResult = new ScanResult();
scanResult.level = -60;
@@ -322,7 +321,6 @@ public class PasspointNetworkScoreTest {
NetworkDetail networkDetail = mock(NetworkDetail.class);
when(networkDetail.isInternet()).thenReturn(internetAccess);
when(networkDetail.getAnt()).thenReturn(networkType);
- when(networkDetail.getANQPElements()).thenReturn(anqpElements);
// Setup ScanDetail.
ScanDetail scanDetail = mock(ScanDetail.class);
@@ -341,9 +339,9 @@ public class PasspointNetworkScoreTest {
public void calculateScore() throws Exception {
for (TestData data : TEST_DATA_LIST) {
ScanDetail scanDetail = generateScanDetail(data.rssiLevel, data.internetAccess,
- data.networkType, data.anqpElements);
+ data.networkType);
assertEquals(data.expectedScore, PasspointNetworkScore.calculateScore(
- data.isHomeProvider, scanDetail, data.isActiveNetwork));
+ data.isHomeProvider, scanDetail, data.anqpElements, data.isActiveNetwork));
}
}