diff options
Diffstat (limited to 'libs')
4 files changed, 167 insertions, 31 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/PasspointWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java index 3e2419faf..ec16f8d93 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java @@ -346,26 +346,18 @@ public class PasspointWifiEntry extends WifiEntry { throws IllegalArgumentException { mWifiConfig = wifiConfig; mSecurity = getSecurityTypeFromWifiConfiguration(wifiConfig); - - if (homeScanResults == null) { - homeScanResults = new ArrayList<>(); - } - if (roamingScanResults == null) { - roamingScanResults = new ArrayList<>(); - } - - ScanResult bestScanResult; - if (homeScanResults.isEmpty() && !roamingScanResults.isEmpty()) { + mIsRoaming = false; + ScanResult bestScanResult = null; + if (homeScanResults != null && !homeScanResults.isEmpty()) { + bestScanResult = getBestScanResultByLevel(homeScanResults); + } else if (roamingScanResults != null && !roamingScanResults.isEmpty()) { mIsRoaming = true; bestScanResult = getBestScanResultByLevel(roamingScanResults); - } else { - mIsRoaming = false; - bestScanResult = getBestScanResultByLevel(homeScanResults); } - if (bestScanResult == null) { mLevel = WIFI_LEVEL_UNREACHABLE; } else { + mWifiConfig.SSID = "\"" + bestScanResult.SSID + "\""; mLevel = mWifiManager.calculateSignalLevel(bestScanResult.level); } diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java index 21d3f2c27..e452003f7 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java @@ -61,6 +61,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -217,8 +218,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 +276,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); @@ -360,18 +371,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 +506,9 @@ public class WifiPickerTracker extends BaseWifiTracker { for (WifiEntry entry : mPasspointWifiEntryCache.values()) { entry.updateConnectionInfo(wifiInfo, networkInfo); } + for (WifiEntry entry : mOsuWifiEntryCache.values()) { + entry.updateConnectionInfo(wifiInfo, networkInfo); + } } /** |