summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Niwa <daisuke.niwa@sony.com>2018-06-27 13:42:10 +0900
committerDaichi Ueura <daichi.ueura@sony.com>2018-09-11 10:42:40 +0900
commit8c414b5cc1f930424497bc26e51837070f5af9a8 (patch)
treefbe3f21f0aa91ee34be982d6b853bd2050617598
parent9666cb415d7d44a86cfb0b7ec1df6e6317fe3259 (diff)
downloadwifi-8c414b5cc1f930424497bc26e51837070f5af9a8.tar.gz
Update SIM status when SIM is removed
The device tries to connect to AP continuously even though SIM has been already removed. This is because SIM status is not updated when SIM is removed. Bug: 113559708 Test: Manual Test: run unit tests Change-Id: I1bd0ab918fec1fa2dfc6b21a6e3ffd919e4741d5
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java31
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java84
2 files changed, 100 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index 0b70dbf4e..bbffdc827 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -2463,21 +2463,22 @@ public class WifiConfigManager {
*/
public void resetSimNetworks(boolean simPresent) {
if (mVerboseLoggingEnabled) localLog("resetSimNetworks");
- for (WifiConfiguration config : getInternalConfiguredNetworks()) {
- if (TelephonyUtil.isSimConfig(config)) {
- Pair<String, String> currentIdentity = null;
- if (simPresent) {
- currentIdentity = TelephonyUtil.getSimIdentity(mTelephonyManager,
- new TelephonyUtil(), config);
- }
- // Update the loaded config
- if (currentIdentity == null) {
- Log.d(TAG, "Identity is null");
- return;
- }
- config.enterpriseConfig.setIdentity(currentIdentity.first);
- if (config.enterpriseConfig.getEapMethod() != WifiEnterpriseConfig.Eap.PEAP) {
- config.enterpriseConfig.setAnonymousIdentity("");
+ if (simPresent) {
+ for (WifiConfiguration config : getInternalConfiguredNetworks()) {
+ if (TelephonyUtil.isSimConfig(config)) {
+ Pair<String, String> currentIdentity =
+ TelephonyUtil.getSimIdentity(mTelephonyManager,
+ new TelephonyUtil(), config);
+
+ // Update the loaded config
+ if (currentIdentity == null) {
+ Log.d(TAG, "Identity is null");
+ break;
+ }
+ config.enterpriseConfig.setIdentity(currentIdentity.first);
+ if (config.enterpriseConfig.getEapMethod() != WifiEnterpriseConfig.Eap.PEAP) {
+ config.enterpriseConfig.setAnonymousIdentity("");
+ }
}
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index a4bc61aa1..4a7ad50d6 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -3563,6 +3563,90 @@ public class WifiConfigManagerTest {
assertEquals(newMac, retrievedConfig.getRandomizedMacAddress());
}
+ /**
+ * Verifies that the method resetSimNetworks updates SIM presence status and SIM configs.
+ */
+ @Test
+ public void testResetSimNetworks() {
+ String expectedIdentity = "13214561234567890@wlan.mnc456.mcc321.3gppnetwork.org";
+ when(mTelephonyManager.getSubscriberId()).thenReturn("3214561234567890");
+ when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY);
+ when(mTelephonyManager.getSimOperator()).thenReturn("321456");
+ when(mTelephonyManager.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null);
+
+ WifiConfiguration network = WifiConfigurationTestUtil.createEapNetwork();
+ WifiConfiguration simNetwork = WifiConfigurationTestUtil.createEapNetwork(
+ WifiEnterpriseConfig.Eap.SIM, WifiEnterpriseConfig.Phase2.NONE);
+ WifiConfiguration peapSimNetwork = WifiConfigurationTestUtil.createEapNetwork(
+ WifiEnterpriseConfig.Eap.PEAP, WifiEnterpriseConfig.Phase2.SIM);
+ network.enterpriseConfig.setIdentity("identity1");
+ network.enterpriseConfig.setAnonymousIdentity("anonymous_identity1");
+ simNetwork.enterpriseConfig.setIdentity("identity2");
+ simNetwork.enterpriseConfig.setAnonymousIdentity("anonymous_identity2");
+ peapSimNetwork.enterpriseConfig.setIdentity("identity3");
+ peapSimNetwork.enterpriseConfig.setAnonymousIdentity("anonymous_identity3");
+ verifyAddNetworkToWifiConfigManager(network);
+ verifyAddNetworkToWifiConfigManager(simNetwork);
+ verifyAddNetworkToWifiConfigManager(peapSimNetwork);
+
+ // Verify SIM is not present initially.
+ assertFalse(mWifiConfigManager.isSimPresent());
+
+ // Call resetSimNetworks with true(SIM is present).
+ mWifiConfigManager.resetSimNetworks(true);
+
+ // Verify SIM is present, SIM configs are reset and non-SIM configs are not changed.
+ assertTrue(mWifiConfigManager.isSimPresent());
+ WifiConfigurationTestUtil.assertConfigurationEqualForConfigManagerAddOrUpdate(
+ network,
+ mWifiConfigManager.getConfiguredNetworkWithPassword(network.networkId));
+ WifiConfiguration retrievedSimNetwork =
+ mWifiConfigManager.getConfiguredNetwork(simNetwork.networkId);
+ assertEquals(expectedIdentity, retrievedSimNetwork.enterpriseConfig.getIdentity());
+ assertTrue(retrievedSimNetwork.enterpriseConfig.getAnonymousIdentity().isEmpty());
+ WifiConfiguration retrievedPeapSimNetwork =
+ mWifiConfigManager.getConfiguredNetwork(peapSimNetwork.networkId);
+ assertEquals(expectedIdentity, retrievedPeapSimNetwork.enterpriseConfig.getIdentity());
+ assertFalse(retrievedPeapSimNetwork.enterpriseConfig.getAnonymousIdentity().isEmpty());
+
+ // Call resetSimNetworks with false(SIM is not present).
+ when(mTelephonyManager.getSubscriberId()).thenReturn("3214561234567891");
+ retrievedSimNetwork.enterpriseConfig.setAnonymousIdentity("anonymous_identity22");
+ verifyUpdateNetworkToWifiConfigManagerWithoutIpChange(retrievedSimNetwork);
+ mWifiConfigManager.resetSimNetworks(false);
+
+ // Verify SIM is not present and all configs are not changed.
+ assertFalse(mWifiConfigManager.isSimPresent());
+ WifiConfigurationTestUtil.assertConfigurationEqualForConfigManagerAddOrUpdate(
+ network,
+ mWifiConfigManager.getConfiguredNetworkWithPassword(network.networkId));
+ WifiConfigurationTestUtil.assertConfigurationEqualForConfigManagerAddOrUpdate(
+ retrievedSimNetwork,
+ mWifiConfigManager.getConfiguredNetworkWithPassword(simNetwork.networkId));
+ WifiConfigurationTestUtil.assertConfigurationEqualForConfigManagerAddOrUpdate(
+ retrievedPeapSimNetwork,
+ mWifiConfigManager.getConfiguredNetworkWithPassword(peapSimNetwork.networkId));
+ }
+
+ /**
+ * Verifies that the method resetSimNetworks updates SIM presence status if
+ * getSimIdentity returns null.
+ */
+ @Test
+ public void testResetSimNetworksWithNullIdentity() {
+ WifiConfiguration simNetwork = WifiConfigurationTestUtil.createEapNetwork(
+ WifiEnterpriseConfig.Eap.SIM, WifiEnterpriseConfig.Phase2.NONE);
+ verifyAddNetworkToWifiConfigManager(simNetwork);
+
+ assertFalse(mWifiConfigManager.isSimPresent());
+
+ mWifiConfigManager.resetSimNetworks(true);
+ assertTrue(mWifiConfigManager.isSimPresent());
+
+ mWifiConfigManager.resetSimNetworks(false);
+ assertFalse(mWifiConfigManager.isSimPresent());
+ }
+
private NetworkUpdateResult verifyAddOrUpdateNetworkWithProxySettingsAndPermissions(
boolean withNetworkSettings,
boolean withProfileOwnerPolicy,