diff options
3 files changed, 138 insertions, 0 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java index a814a9f938a6..a39cf85d2161 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.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; @@ -134,6 +135,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); /** @@ -191,6 +195,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); @@ -227,6 +238,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(); @@ -283,6 +303,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; } /** @@ -658,6 +681,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) { @@ -700,6 +735,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(), @@ -733,6 +771,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. @@ -1022,6 +1062,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) { @@ -1043,6 +1086,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) { @@ -1071,6 +1117,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; diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/TestAccessPointBuilder.java b/packages/SettingsLib/src/com/android/settingslib/wifi/TestAccessPointBuilder.java index 731a6072218b..93bf3c7ec20e 100644 --- a/packages/SettingsLib/src/com/android/settingslib/wifi/TestAccessPointBuilder.java +++ b/packages/SettingsLib/src/com/android/settingslib/wifi/TestAccessPointBuilder.java @@ -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; + } } 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 35c730e64ead..ce7611e8e143 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 @@ -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; @@ -472,6 +473,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); |