Merge "SettingsLib: wifi: encapsulate Passpoint configuration in AccessPoint" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
70c429d37a
@@ -37,6 +37,7 @@ import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
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 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
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 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
// 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 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
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 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
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 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
return mConfig;
|
||||
}
|
||||
|
||||
public String getPasspointFqdn() {
|
||||
return mFqdn;
|
||||
}
|
||||
|
||||
public void clearConfig() {
|
||||
mConfig = null;
|
||||
networkId = WifiConfiguration.INVALID_NETWORK_ID;
|
||||
@@ -504,6 +535,8 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
public String getConfigName() {
|
||||
if (mConfig != null && mConfig.isPasspoint()) {
|
||||
return mConfig.providerFriendlyName;
|
||||
} else if (mFqdn != null) {
|
||||
return mProviderFriendlyName;
|
||||
} else {
|
||||
return ssid;
|
||||
}
|
||||
@@ -778,10 +811,20 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
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
|
||||
@@ -857,6 +900,12 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
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) {
|
||||
|
||||
@@ -67,6 +67,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
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);
|
||||
|
||||
@@ -18,6 +18,8 @@ package com.android.settingslib.wifi;
|
||||
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.ScanResult;
|
||||
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 @@ public class AccessPointTest {
|
||||
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 @@ public class AccessPointTest {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ public class TestAccessPointBuilder {
|
||||
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 @@ public class TestAccessPointBuilder {
|
||||
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 @@ public class TestAccessPointBuilder {
|
||||
ssid = newSsid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAccessPointBuilder setFqdn(String fqdn) {
|
||||
mFqdn = fqdn;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAccessPointBuilder setProviderFriendlyName(String friendlyName) {
|
||||
mProviderFriendlyName = friendlyName;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user