From 48c93da3c53650a62bc827199840137417c0825a Mon Sep 17 00:00:00 2001 From: Peter Qiu Date: Thu, 9 Mar 2017 13:28:47 -0800 Subject: hotspot2: add support for WifiStateMachine#syncGetMatchingWifiConfig This function will try to match a Passpoint AP to an installed Passpoint provider. Once a match is found, it will generate and return a WifiConfiguration for the given Passpoint AP, which will contain all necessary credentials for connecting to it. Note that, the generated configuration is not added to WifiConfigManager. The consumer of this WifiConfiguration (e.g. Settings app) can use this WifiConfiguration to initiate a connection via WifiManager's API. This operation is only supported in client mode, since PasspointManager might issue ANQP requests when matching scan result to a provider. Bug: 35888100 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: install Global Reach Passpoint profile and verify the Global Reach Passpoint AP in the Settings UI is shown with "available via xxx" text. Change-Id: I9bbd57819326d285367e89a342f21da79fc33555 --- .../com/android/server/wifi/WifiStateMachine.java | 8 +++++--- .../server/wifi/hotspot2/PasspointManager.java | 24 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index a5dc9375f..2f86743f2 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -1836,7 +1836,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss public WifiConfiguration syncGetMatchingWifiConfig(ScanResult scanResult, AsyncChannel channel) { Message resultMsg = channel.sendMessageSynchronously(CMD_GET_MATCHING_CONFIG, scanResult); - return (WifiConfiguration) resultMsg.obj; + WifiConfiguration config = (WifiConfiguration) resultMsg.obj; + resultMsg.recycle(); + return config; } /** @@ -4952,8 +4954,8 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss } break; case CMD_GET_MATCHING_CONFIG: - // TODO(b/31065385) - replyToMessage(message, message.what, null); + replyToMessage(message, message.what, + mPasspointManager.getMatchingWifiConfig((ScanResult) message.obj)); break; case CMD_RECONNECT: mWifiConnectivityManager.forceConnectivityScan(); diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java index 29656fd89..c3acd39c3 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java @@ -47,6 +47,7 @@ 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 com.android.server.wifi.util.ScanResultUtil; import java.util.ArrayList; import java.util.HashMap; @@ -411,6 +412,29 @@ public class PasspointManager { return new HashMap(); } + /** + * Match the given WiFi AP to an installed Passpoint provider. A {@link WifiConfiguration} + * will be generated and returned if a match is found. The returned {@link WifiConfiguration} + * will contained all the necessary credentials for connecting to the given WiFi AP. + * + * A {code null} will be returned if no matching provider is found. + * + * @param scanResult The scan result of the given AP + * @return {@link WifiConfiguration} + */ + public WifiConfiguration getMatchingWifiConfig(ScanResult scanResult) { + if (scanResult == null) { + return null; + } + Pair matchedProvider = matchProvider(scanResult); + if (matchedProvider == null) { + return null; + } + WifiConfiguration config = matchedProvider.first.getWifiConfig(); + config.SSID = ScanResultUtil.createQuotedSSID(scanResult.SSID); + return config; + } + /** * Add a legacy Passpoint configuration represented by a {@link WifiConfiguration}. * -- cgit v1.2.3