diff options
4 files changed, 56 insertions, 8 deletions
diff --git a/service/java/com/android/server/wifi/hotspot2/ANQPRequestManager.java b/service/java/com/android/server/wifi/hotspot2/ANQPRequestManager.java index dfdf4ad16..a050b1606 100644 --- a/service/java/com/android/server/wifi/hotspot2/ANQPRequestManager.java +++ b/service/java/com/android/server/wifi/hotspot2/ANQPRequestManager.java @@ -77,7 +77,8 @@ public class ANQPRequestManager { private static final List<Constants.ANQPElementType> R2_ANQP_BASE_SET = Arrays.asList( Constants.ANQPElementType.HSFriendlyName, Constants.ANQPElementType.HSWANMetrics, - Constants.ANQPElementType.HSConnCapability); + Constants.ANQPElementType.HSConnCapability, + Constants.ANQPElementType.HSOSUProviders); /** * Class to keep track of AP status for ANQP requests. diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java index ea7181321..deec28464 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java @@ -18,7 +18,9 @@ package com.android.server.wifi.hotspot2; import static android.net.wifi.WifiManager.ACTION_PASSPOINT_DEAUTH_IMMINENT; import static android.net.wifi.WifiManager.ACTION_PASSPOINT_ICON; +import static android.net.wifi.WifiManager.ACTION_PASSPOINT_OSU_PROVIDERS_LIST; import static android.net.wifi.WifiManager.ACTION_PASSPOINT_SUBSCRIPTION_REMEDIATION; +import static android.net.wifi.WifiManager.EXTRA_ANQP_ELEMENT_DATA; import static android.net.wifi.WifiManager.EXTRA_BSSID_LONG; import static android.net.wifi.WifiManager.EXTRA_DELAY; import static android.net.wifi.WifiManager.EXTRA_ESS; @@ -47,6 +49,7 @@ 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.hotspot2.anqp.RawByteElement; import com.android.server.wifi.util.InformationElementUtil; import com.android.server.wifi.util.ScanResultUtil; @@ -118,6 +121,18 @@ public class PasspointManager { // Add new entry to the cache. mAnqpCache.addEntry(anqpKey, anqpElements); + + // Broadcast OSU providers info. + if (anqpElements.containsKey(Constants.ANQPElementType.HSOSUProviders)) { + RawByteElement osuProviders = (RawByteElement) anqpElements.get( + Constants.ANQPElementType.HSOSUProviders); + Intent intent = new Intent(ACTION_PASSPOINT_OSU_PROVIDERS_LIST); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); + intent.putExtra(EXTRA_BSSID_LONG, bssid); + intent.putExtra(EXTRA_ANQP_ELEMENT_DATA, osuProviders.getPayload()); + mContext.sendBroadcastAsUser(intent, UserHandle.ALL, + android.Manifest.permission.ACCESS_WIFI_STATE); + } } @Override @@ -313,11 +328,6 @@ public class PasspointManager { * @return A pair of {@link PasspointProvider} and match status. */ public Pair<PasspointProvider, PasspointMatch> matchProvider(ScanResult scanResult) { - // Nothing to be done if no Passpoint provider is installed. - if (mProviders.isEmpty()) { - return null; - } - // Retrieve the relevant information elements, mainly Roaming Consortium IE and Hotspot 2.0 // Vendor Specific IE. InformationElementUtil.RoamingConsortium roamingConsortium = 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 022d22dae..10c147274 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPRequestManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPRequestManagerTest.java @@ -71,7 +71,8 @@ public class ANQPRequestManagerTest { Constants.ANQPElementType.ANQPDomName, Constants.ANQPElementType.HSFriendlyName, Constants.ANQPElementType.HSWANMetrics, - Constants.ANQPElementType.HSConnCapability); + Constants.ANQPElementType.HSConnCapability, + Constants.ANQPElementType.HSOSUProviders); private static final List<Constants.ANQPElementType> R1R2_ANQP_WITH_RC = Arrays.asList( Constants.ANQPElementType.ANQPVenueName, @@ -82,7 +83,8 @@ public class ANQPRequestManagerTest { Constants.ANQPElementType.ANQPRoamingConsortium, Constants.ANQPElementType.HSFriendlyName, Constants.ANQPElementType.HSWANMetrics, - Constants.ANQPElementType.HSConnCapability); + Constants.ANQPElementType.HSConnCapability, + Constants.ANQPElementType.HSOSUProviders); @Mock PasspointEventHandler mHandler; @Mock Clock mClock; 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 28d7e2df0..cea1c172d 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -18,7 +18,9 @@ package com.android.server.wifi.hotspot2; import static android.net.wifi.WifiManager.ACTION_PASSPOINT_DEAUTH_IMMINENT; import static android.net.wifi.WifiManager.ACTION_PASSPOINT_ICON; +import static android.net.wifi.WifiManager.ACTION_PASSPOINT_OSU_PROVIDERS_LIST; import static android.net.wifi.WifiManager.ACTION_PASSPOINT_SUBSCRIPTION_REMEDIATION; +import static android.net.wifi.WifiManager.EXTRA_ANQP_ELEMENT_DATA; import static android.net.wifi.WifiManager.EXTRA_BSSID_LONG; import static android.net.wifi.WifiManager.EXTRA_DELAY; import static android.net.wifi.WifiManager.EXTRA_ESS; @@ -70,6 +72,7 @@ import com.android.server.wifi.WifiNative; import com.android.server.wifi.hotspot2.anqp.ANQPElement; import com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType; import com.android.server.wifi.hotspot2.anqp.DomainNameElement; +import com.android.server.wifi.hotspot2.anqp.RawByteElement; import com.android.server.wifi.util.ScanResultUtil; import org.junit.Before; @@ -282,6 +285,38 @@ public class PasspointManagerTest { when(mAnqpRequestManager.onRequestCompleted(TEST_BSSID, true)).thenReturn(TEST_ANQP_KEY); mCallbacks.onANQPResponse(TEST_BSSID, anqpElementMap); verify(mAnqpCache).addEntry(TEST_ANQP_KEY, anqpElementMap); + verify(mContext, never()).sendBroadcastAsUser(any(Intent.class), any(UserHandle.class), + any(String.class)); + } + + /** + * Verify that the ANQP elements will be added to the AQNP cache and an + * {@link WifiManager#ACTION_PASSPOINT_OSU_PROVIDER_LIST} intent will be broadcasted when + * receiving an ANQP response containing OSU Providers element. + * + * @throws Exception + */ + @Test + public void anqpResponseWithOSUProviders() throws Exception { + Map<ANQPElementType, ANQPElement> anqpElementMap = new HashMap<>(); + byte[] testData = new byte[] {0x12, 0x34, 0x56, 0x78}; + anqpElementMap.put(ANQPElementType.HSOSUProviders, + new RawByteElement(ANQPElementType.HSOSUProviders, testData)); + + when(mAnqpRequestManager.onRequestCompleted(TEST_BSSID, true)).thenReturn(TEST_ANQP_KEY); + mCallbacks.onANQPResponse(TEST_BSSID, anqpElementMap); + verify(mAnqpCache).addEntry(TEST_ANQP_KEY, anqpElementMap); + + // Verify the broadcast intent for OSU providers. + ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class); + verify(mContext).sendBroadcastAsUser(intent.capture(), eq(UserHandle.ALL), + eq(android.Manifest.permission.ACCESS_WIFI_STATE)); + assertEquals(ACTION_PASSPOINT_OSU_PROVIDERS_LIST, intent.getValue().getAction()); + assertTrue(intent.getValue().getExtras().containsKey(EXTRA_BSSID_LONG)); + assertEquals(TEST_BSSID, intent.getValue().getExtras().getLong(EXTRA_BSSID_LONG)); + assertTrue(intent.getValue().getExtras().containsKey(EXTRA_ANQP_ELEMENT_DATA)); + assertTrue(Arrays.equals(testData, + intent.getValue().getExtras().getByteArray(EXTRA_ANQP_ELEMENT_DATA))); } /** |