Merge "SettingsLib: wifi: encapsulate Passpoint configuration in AccessPoint" into oc-dev
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
index 45004c4..1ea4183 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
@@ -37,6 +37,7 @@
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiNetworkScoreCache;
+import android.net.wifi.hotspot2.PasspointConfiguration;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -100,6 +101,8 @@
static final String KEY_PSKTYPE = "key_psktype";
static final String KEY_SCANRESULTCACHE = "key_scanresultcache";
static final String KEY_CONFIG = "key_config";
+ static final String KEY_FQDN = "key_fqdn";
+ static final String KEY_PROVIDER_FRIENDLY_NAME = "key_provider_friendly_name";
static final AtomicInteger sLastId = new AtomicInteger(0);
/**
@@ -150,6 +153,13 @@
// used to co-relate internal vs returned accesspoint.
int mId;
+ /**
+ * Information associated with the {@link PasspointConfiguration}. Only maintaining
+ * the relevant info to preserve spaces.
+ */
+ private String mFqdn;
+ private String mProviderFriendlyName;
+
public AccessPoint(Context context, Bundle savedState) {
mContext = context;
mConfig = savedState.getParcelable(KEY_CONFIG);
@@ -177,21 +187,32 @@
mScanResultCache.put(result.BSSID, result);
}
}
+ if (savedState.containsKey(KEY_FQDN)) {
+ mFqdn = savedState.getString(KEY_FQDN);
+ }
+ if (savedState.containsKey(KEY_PROVIDER_FRIENDLY_NAME)) {
+ mProviderFriendlyName = savedState.getString(KEY_PROVIDER_FRIENDLY_NAME);
+ }
update(mConfig, mInfo, mNetworkInfo);
updateRssi();
updateSeen();
mId = sLastId.incrementAndGet();
}
- AccessPoint(Context context, ScanResult result) {
+ public AccessPoint(Context context, WifiConfiguration config) {
mContext = context;
- initWithScanResult(result);
+ loadConfig(config);
mId = sLastId.incrementAndGet();
}
- AccessPoint(Context context, WifiConfiguration config) {
+ /**
+ * Initialize an AccessPoint object for a {@link PasspointConfiguration}. This is mainly
+ * used by "Saved Networks" page for managing the saved {@link PasspointConfiguration}.
+ */
+ public AccessPoint(Context context, PasspointConfiguration config) {
mContext = context;
- loadConfig(config);
+ mFqdn = config.getHomeSp().getFqdn();
+ mProviderFriendlyName = config.getHomeSp().getFriendlyName();
mId = sLastId.incrementAndGet();
}
@@ -200,6 +221,12 @@
copyFrom(other);
}
+ AccessPoint(Context context, ScanResult result) {
+ mContext = context;
+ initWithScanResult(result);
+ mId = sLastId.incrementAndGet();
+ }
+
/**
* Copy accesspoint information. NOTE: We do not copy tag information because that is never
* set on the internal copy.
@@ -368,6 +395,10 @@
return mConfig;
}
+ public String getPasspointFqdn() {
+ return mFqdn;
+ }
+
public void clearConfig() {
mConfig = null;
networkId = WifiConfiguration.INVALID_NETWORK_ID;
@@ -504,6 +535,8 @@
public String getConfigName() {
if (mConfig != null && mConfig.isPasspoint()) {
return mConfig.providerFriendlyName;
+ } else if (mFqdn != null) {
+ return mProviderFriendlyName;
} else {
return ssid;
}
@@ -778,11 +811,21 @@
mNetworkInfo != null && mNetworkInfo.getState() != State.DISCONNECTED;
}
+ /**
+ * Return true if this AccessPoint represents a Passpoint AP.
+ */
public boolean isPasspoint() {
return mConfig != null && mConfig.isPasspoint();
}
/**
+ * Return true if this AccessPoint represents a Passpoint provider configuration.
+ */
+ public boolean isPasspointConfig() {
+ return mFqdn != null;
+ }
+
+ /**
* Return whether the given {@link WifiInfo} is for this access point.
* If the current AP does not have a network Id then the config is used to
* match based on SSID and security.
@@ -857,6 +900,12 @@
if (mNetworkInfo != null) {
savedState.putParcelable(KEY_NETWORKINFO, mNetworkInfo);
}
+ if (mFqdn != null) {
+ savedState.putString(KEY_FQDN, mFqdn);
+ }
+ if (mProviderFriendlyName != null) {
+ savedState.putString(KEY_PROVIDER_FRIENDLY_NAME, mProviderFriendlyName);
+ }
}
public void setListener(AccessPointListener listener) {
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
index 1f86f8b..50f294c 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
@@ -67,6 +67,7 @@
public class WifiTracker {
// TODO(sghuman): Document remaining methods with @UiThread and @WorkerThread where possible.
// TODO(sghuman): Refactor to avoid calling certain methods on the UiThread.
+ // TODO(b/36733768): Remove flag includeSaved and includePasspoints.
private static final String TAG = "WifiTracker";
private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java
index b9b4ef3..762d9f8 100644
--- a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java
+++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java
@@ -18,6 +18,8 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
+import static org.junit.Assert.assertTrue;
+
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
@@ -25,6 +27,8 @@
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiSsid;
+import android.net.wifi.hotspot2.PasspointConfiguration;
+import android.net.wifi.hotspot2.pps.HomeSp;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.test.InstrumentationRegistry;
@@ -215,6 +219,17 @@
assertThat(ap.getRssi()).isEqualTo(expectedRssi);
}
+ @Test
+ public void testCreateFromPasspointConfig() {
+ PasspointConfiguration config = new PasspointConfiguration();
+ HomeSp homeSp = new HomeSp();
+ homeSp.setFqdn("test.com");
+ homeSp.setFriendlyName("Test Provider");
+ config.setHomeSp(homeSp);
+ AccessPoint ap = new AccessPoint(mContext, config);
+ assertTrue(ap.isPasspointConfig());
+ }
+
private AccessPoint createAccessPointWithScanResultCache() {
Bundle bundle = new Bundle();
ArrayList<ScanResult> scanResults = new ArrayList<>();
@@ -319,4 +334,15 @@
AccessPoint namedAp = new TestAccessPointBuilder(mContext).setSsid(name).build();
assertThat(namedAp.getSsidStr()).isEqualTo(name);
}
+
+ @Test
+ public void testBuilder_passpointConfig() {
+ String fqdn = "Test.com";
+ String providerFriendlyName = "Test Provider";
+ AccessPoint ap = new TestAccessPointBuilder(mContext).setFqdn(fqdn)
+ .setProviderFriendlyName(providerFriendlyName).build();
+ assertTrue(ap.isPasspointConfig());
+ assertThat(ap.getPasspointFqdn()).isEqualTo(fqdn);
+ assertThat(ap.getConfigName()).isEqualTo(providerFriendlyName);
+ }
}
diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/TestAccessPointBuilder.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/TestAccessPointBuilder.java
index 81bd723..a347203 100644
--- a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/TestAccessPointBuilder.java
+++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/TestAccessPointBuilder.java
@@ -39,6 +39,8 @@
private int networkId = WifiConfiguration.INVALID_NETWORK_ID;
private String ssid = "TestSsid";
private NetworkInfo mNetworkInfo = null;
+ private String mFqdn = null;
+ private String mProviderFriendlyName = null;
Context mContext;
@@ -55,6 +57,12 @@
bundle.putString(AccessPoint.KEY_SSID, ssid);
bundle.putParcelable(AccessPoint.KEY_CONFIG, wifiConig);
bundle.putParcelable(AccessPoint.KEY_NETWORKINFO, mNetworkInfo);
+ if (mFqdn != null) {
+ bundle.putString(AccessPoint.KEY_FQDN, mFqdn);
+ }
+ if (mProviderFriendlyName != null) {
+ bundle.putString(AccessPoint.KEY_PROVIDER_FRIENDLY_NAME, mProviderFriendlyName);
+ }
AccessPoint ap = new AccessPoint(mContext, bundle);
ap.setRssi(mRssi);
return ap;
@@ -128,4 +136,14 @@
ssid = newSsid;
return this;
}
+
+ public TestAccessPointBuilder setFqdn(String fqdn) {
+ mFqdn = fqdn;
+ return this;
+ }
+
+ public TestAccessPointBuilder setProviderFriendlyName(String friendlyName) {
+ mProviderFriendlyName = friendlyName;
+ return this;
+ }
}