Merge "SettingsLib: wifi: add support for tracking carrier Wi-Fi APs" into oc-mr1-dev am: fca9a47ba8
am: 1387d056f9 Change-Id: Iad364bc777c571bac8aa1c31dcdc9e50ed815069
This commit is contained in:
commit
41f3ad1c05
@ -37,6 +37,7 @@ import android.net.wifi.IWifiManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
import android.net.wifi.WifiEnterpriseConfig;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiNetworkScoreCache;
|
||||
@ -140,6 +141,9 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
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 String KEY_IS_CARRIER_AP = "key_is_carrier_ap";
|
||||
static final String KEY_CARRIER_AP_EAP_TYPE = "key_carrier_ap_eap_type";
|
||||
static final String KEY_CARRIER_NAME = "key_carrier_name";
|
||||
static final AtomicInteger sLastId = new AtomicInteger(0);
|
||||
|
||||
/**
|
||||
@ -197,6 +201,13 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
private String mFqdn;
|
||||
private String mProviderFriendlyName;
|
||||
|
||||
private boolean mIsCarrierAp = false;
|
||||
/**
|
||||
* The EAP type {@link WifiEnterpriseConfig.Eap} associated with this AP if it is a carrier AP.
|
||||
*/
|
||||
private int mCarrierApEapType = WifiEnterpriseConfig.Eap.NONE;
|
||||
private String mCarrierName = null;
|
||||
|
||||
public AccessPoint(Context context, Bundle savedState) {
|
||||
mContext = context;
|
||||
mConfig = savedState.getParcelable(KEY_CONFIG);
|
||||
@ -233,6 +244,15 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
if (savedState.containsKey(KEY_PROVIDER_FRIENDLY_NAME)) {
|
||||
mProviderFriendlyName = savedState.getString(KEY_PROVIDER_FRIENDLY_NAME);
|
||||
}
|
||||
if (savedState.containsKey(KEY_IS_CARRIER_AP)) {
|
||||
mIsCarrierAp = savedState.getBoolean(KEY_IS_CARRIER_AP);
|
||||
}
|
||||
if (savedState.containsKey(KEY_CARRIER_AP_EAP_TYPE)) {
|
||||
mCarrierApEapType = savedState.getInt(KEY_CARRIER_AP_EAP_TYPE);
|
||||
}
|
||||
if (savedState.containsKey(KEY_CARRIER_NAME)) {
|
||||
mCarrierName = savedState.getString(KEY_CARRIER_NAME);
|
||||
}
|
||||
update(mConfig, mInfo, mNetworkInfo);
|
||||
updateRssi();
|
||||
updateSeen();
|
||||
@ -291,6 +311,9 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
this.mId = that.mId;
|
||||
this.mSpeed = that.mSpeed;
|
||||
this.mIsScoredNetworkMetered = that.mIsScoredNetworkMetered;
|
||||
this.mIsCarrierAp = that.mIsCarrierAp;
|
||||
this.mCarrierApEapType = that.mCarrierApEapType;
|
||||
this.mCarrierName = that.mCarrierName;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -670,6 +693,18 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isCarrierAp() {
|
||||
return mIsCarrierAp;
|
||||
}
|
||||
|
||||
public int getCarrierApEapType() {
|
||||
return mCarrierApEapType;
|
||||
}
|
||||
|
||||
public String getCarrierName() {
|
||||
return mCarrierName;
|
||||
}
|
||||
|
||||
public String getSavedNetworkSummary() {
|
||||
WifiConfiguration config = mConfig;
|
||||
if (config != null) {
|
||||
@ -712,6 +747,9 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
// This is the active connection on passpoint
|
||||
summary.append(getSummary(mContext, getDetailedState(),
|
||||
false, config.providerFriendlyName));
|
||||
} else if (isActive() && config != null && getDetailedState() == DetailedState.CONNECTED
|
||||
&& mIsCarrierAp) {
|
||||
summary.append(String.format(mContext.getString(R.string.connected_via_carrier), mCarrierName));
|
||||
} else if (isActive()) {
|
||||
// This is the active connection on non-passpoint network
|
||||
summary.append(getSummary(mContext, getDetailedState(),
|
||||
@ -745,6 +783,8 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
}
|
||||
} else if (config != null && config.getNetworkSelectionStatus().isNotRecommended()) {
|
||||
summary.append(mContext.getString(R.string.wifi_disabled_by_recommendation_provider));
|
||||
} else if (mIsCarrierAp) {
|
||||
summary.append(String.format(mContext.getString(R.string.available_via_carrier), mCarrierName));
|
||||
} else if (!isReachable()) { // Wifi out of range
|
||||
summary.append(mContext.getString(R.string.wifi_not_in_range));
|
||||
} else { // In range, not disabled.
|
||||
@ -1024,6 +1064,9 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
mScanResultCache.put(result.BSSID, result);
|
||||
updateRssi();
|
||||
mSeen = result.timestamp; // even if the timestamp is old it is still valid
|
||||
mIsCarrierAp = result.isCarrierAp;
|
||||
mCarrierApEapType = result.carrierApEapType;
|
||||
mCarrierName = result.carrierName;
|
||||
}
|
||||
|
||||
public void saveWifiState(Bundle savedState) {
|
||||
@ -1045,6 +1088,9 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
if (mProviderFriendlyName != null) {
|
||||
savedState.putString(KEY_PROVIDER_FRIENDLY_NAME, mProviderFriendlyName);
|
||||
}
|
||||
savedState.putBoolean(KEY_IS_CARRIER_AP, mIsCarrierAp);
|
||||
savedState.putInt(KEY_CARRIER_AP_EAP_TYPE, mCarrierApEapType);
|
||||
savedState.putString(KEY_CARRIER_NAME, mCarrierName);
|
||||
}
|
||||
|
||||
public void setListener(AccessPointListener listener) {
|
||||
@ -1073,6 +1119,12 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
mAccessPointListener.onAccessPointChanged(this);
|
||||
}
|
||||
|
||||
// The carrier info in the ScanResult is set by the platform based on the SSID and will
|
||||
// always be the same for all matching scan results.
|
||||
mIsCarrierAp = result.isCarrierAp;
|
||||
mCarrierApEapType = result.carrierApEapType;
|
||||
mCarrierName = result.carrierName;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -53,6 +53,8 @@ public class TestAccessPointBuilder {
|
||||
private int mSecurity = AccessPoint.SECURITY_NONE;
|
||||
private WifiConfiguration mWifiConfig;
|
||||
private WifiInfo mWifiInfo;
|
||||
private boolean mIsCarrierAp = false;
|
||||
private String mCarrierName = null;
|
||||
|
||||
Context mContext;
|
||||
private ArrayList<ScanResult> mScanResultCache;
|
||||
@ -85,6 +87,10 @@ public class TestAccessPointBuilder {
|
||||
}
|
||||
bundle.putInt(AccessPoint.KEY_SECURITY, mSecurity);
|
||||
bundle.putInt(AccessPoint.KEY_SPEED, mSpeed);
|
||||
bundle.putBoolean(AccessPoint.KEY_IS_CARRIER_AP, mIsCarrierAp);
|
||||
if (mCarrierName != null) {
|
||||
bundle.putString(AccessPoint.KEY_CARRIER_NAME, mCarrierName);
|
||||
}
|
||||
|
||||
AccessPoint ap = new AccessPoint(mContext, bundle);
|
||||
ap.setRssi(mRssi);
|
||||
@ -222,4 +228,14 @@ public class TestAccessPointBuilder {
|
||||
mScanResultCache = scanResultCache;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAccessPointBuilder setIsCarrierAp(boolean isCarrierAp) {
|
||||
mIsCarrierAp = isCarrierAp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAccessPointBuilder setCarrierName(String carrierName) {
|
||||
mCarrierName = carrierName;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import android.net.ScoredNetwork;
|
||||
import android.net.WifiKey;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiEnterpriseConfig;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiNetworkScoreCache;
|
||||
import android.net.wifi.WifiSsid;
|
||||
@ -491,6 +492,75 @@ public class AccessPointTest {
|
||||
R.string.wifi_check_password_try_again));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryString_showsAvaiableViaCarrier() {
|
||||
String carrierName = "Test Carrier";
|
||||
ScanResult result = new ScanResult();
|
||||
result.BSSID = "00:11:22:33:44:55";
|
||||
result.capabilities = "EAP";
|
||||
result.isCarrierAp = true;
|
||||
result.carrierApEapType = WifiEnterpriseConfig.Eap.SIM;
|
||||
result.carrierName = carrierName;
|
||||
|
||||
AccessPoint ap = new AccessPoint(mContext, result);
|
||||
assertThat(ap.getSummary()).isEqualTo(String.format(mContext.getString(
|
||||
R.string.available_via_carrier), carrierName));
|
||||
assertThat(ap.isCarrierAp()).isEqualTo(true);
|
||||
assertThat(ap.getCarrierApEapType()).isEqualTo(WifiEnterpriseConfig.Eap.SIM);
|
||||
assertThat(ap.getCarrierName()).isEqualTo(carrierName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryString_showsConnectedViaCarrier() {
|
||||
int networkId = 123;
|
||||
int rssi = -55;
|
||||
String carrierName = "Test Carrier";
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.networkId = networkId;
|
||||
WifiInfo wifiInfo = new WifiInfo();
|
||||
wifiInfo.setNetworkId(networkId);
|
||||
wifiInfo.setRssi(rssi);
|
||||
|
||||
NetworkInfo networkInfo =
|
||||
new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
|
||||
networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
|
||||
|
||||
AccessPoint ap = new TestAccessPointBuilder(mContext)
|
||||
.setNetworkInfo(networkInfo)
|
||||
.setNetworkId(networkId)
|
||||
.setRssi(rssi)
|
||||
.setWifiInfo(wifiInfo)
|
||||
.setIsCarrierAp(true)
|
||||
.setCarrierName(carrierName)
|
||||
.build();
|
||||
assertThat(ap.getSummary()).isEqualTo(String.format(mContext.getString(
|
||||
R.string.connected_via_carrier), carrierName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateScanResultWithCarrierInfo() {
|
||||
String ssid = "ssid";
|
||||
AccessPoint ap = new TestAccessPointBuilder(mContext).setSsid(ssid).build();
|
||||
assertThat(ap.isCarrierAp()).isEqualTo(false);
|
||||
assertThat(ap.getCarrierApEapType()).isEqualTo(WifiEnterpriseConfig.Eap.NONE);
|
||||
assertThat(ap.getCarrierName()).isEqualTo(null);
|
||||
|
||||
int carrierApEapType = WifiEnterpriseConfig.Eap.SIM;
|
||||
String carrierName = "Test Carrier";
|
||||
ScanResult scanResult = new ScanResult();
|
||||
scanResult.SSID = ssid;
|
||||
scanResult.BSSID = "00:11:22:33:44:55";
|
||||
scanResult.capabilities = "";
|
||||
scanResult.isCarrierAp = true;
|
||||
scanResult.carrierApEapType = carrierApEapType;
|
||||
scanResult.carrierName = carrierName;
|
||||
assertThat(ap.update(scanResult)).isTrue();
|
||||
|
||||
assertThat(ap.isCarrierAp()).isEqualTo(true);
|
||||
assertThat(ap.getCarrierApEapType()).isEqualTo(carrierApEapType);
|
||||
assertThat(ap.getCarrierName()).isEqualTo(carrierName);
|
||||
}
|
||||
|
||||
private ScoredNetwork buildScoredNetworkWithMockBadgeCurve() {
|
||||
Bundle attr1 = new Bundle();
|
||||
attr1.putParcelable(ScoredNetwork.ATTRIBUTES_KEY_BADGING_CURVE, mockBadgeCurve);
|
||||
|
Loading…
x
Reference in New Issue
Block a user