diff options
author | Jeremy Chow <ktchow@google.com> | 2023-06-02 07:54:25 +0000 |
---|---|---|
committer | Jeremy Chow <ktchow@google.com> | 2023-07-11 09:51:36 +0000 |
commit | 8bde777b9c64571e43da2ec8e3cd15fbdd9697a8 (patch) | |
tree | 1c63f43962180057fb2a8ca672769f99faaa0eae | |
parent | 22e14b73f74af7bfa002ec84346e00ac132eea34 (diff) | |
download | Iwlan-8bde777b9c64571e43da2ec8e3cd15fbdd9697a8.tar.gz |
Reset carrier error policy in ErrorPolicyManager if new carrier has no error policy.
Bug: 279676451
Test: atest IwlanTests
Change-Id: Idff2728be6fe12c0e7d651d6a6ca46738a49d0c8
-rw-r--r-- | src/com/google/android/iwlan/ErrorPolicyManager.java | 15 | ||||
-rw-r--r-- | test/com/google/android/iwlan/ErrorPolicyManagerTest.java | 53 |
2 files changed, 61 insertions, 7 deletions
diff --git a/src/com/google/android/iwlan/ErrorPolicyManager.java b/src/com/google/android/iwlan/ErrorPolicyManager.java index 88e9a7f..53a032c 100644 --- a/src/com/google/android/iwlan/ErrorPolicyManager.java +++ b/src/com/google/android/iwlan/ErrorPolicyManager.java @@ -51,6 +51,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -157,7 +158,7 @@ public class ErrorPolicyManager { private int carrierId = TelephonyManager.UNKNOWN_CARRIER_ID; - private String carrierConfigErrorPolicyString; + private String mCarrierConfigErrorPolicyString; @VisibleForTesting static final String KEY_ERROR_POLICY_CONFIG_STRING = "iwlan.key_error_policy_config_string"; @@ -501,7 +502,7 @@ public class ErrorPolicyManager { throw new AssertionError(e); } - carrierConfigErrorPolicyString = null; + mCarrierConfigErrorPolicyString = null; readFromCarrierConfig(IwlanHelper.getCarrierId(mContext, mSlotId)); updateUnthrottlingEvents(); } @@ -792,13 +793,15 @@ public class ErrorPolicyManager { IwlanHelper.getConfig(KEY_ERROR_POLICY_CONFIG_STRING, mContext, mSlotId); if (carrierConfigErrorPolicy == null) { Log.e(LOG_TAG, "ErrorPolicy from Carrier Config is NULL"); + mCarrierConfigPolicies.clear(); + mCarrierConfigErrorPolicyString = null; return; } try { Map<String, List<ErrorPolicy>> errorPolicies = readErrorPolicies(new JSONArray(carrierConfigErrorPolicy)); if (errorPolicies.size() > 0) { - carrierConfigErrorPolicyString = carrierConfigErrorPolicy; + mCarrierConfigErrorPolicyString = carrierConfigErrorPolicy; carrierId = currentCarrierId; mCarrierConfigPolicies.clear(); mCarrierConfigPolicies.putAll(errorPolicies); @@ -809,7 +812,7 @@ public class ErrorPolicyManager { "Unable to parse the ErrorPolicy from CarrierConfig\n" + carrierConfigErrorPolicy); mCarrierConfigPolicies.clear(); - carrierConfigErrorPolicyString = null; + mCarrierConfigErrorPolicyString = null; e.printStackTrace(); } } @@ -1175,9 +1178,9 @@ public class ErrorPolicyManager { String errorPolicyConfig = IwlanHelper.getConfig(KEY_ERROR_POLICY_CONFIG_STRING, mContext, mSlotId); return (currentCarrierId != carrierId) - || (carrierConfigErrorPolicyString == null) + || (mCarrierConfigErrorPolicyString == null) || (errorPolicyConfig != null - && !carrierConfigErrorPolicyString.equals(errorPolicyConfig)); + && !Objects.equals(mCarrierConfigErrorPolicyString, errorPolicyConfig)); } private final class EpmHandler extends Handler { diff --git a/test/com/google/android/iwlan/ErrorPolicyManagerTest.java b/test/com/google/android/iwlan/ErrorPolicyManagerTest.java index 1c15e41..f9ec9fa 100644 --- a/test/com/google/android/iwlan/ErrorPolicyManagerTest.java +++ b/test/com/google/android/iwlan/ErrorPolicyManagerTest.java @@ -411,6 +411,53 @@ public class ErrorPolicyManagerTest { } @Test + public void testNullCarrierConfig() throws Exception { + String apn = "ims"; + String config = + "[{" + + "\"ApnName\": \"" + + apn + + "\"," + + "\"ErrorTypes\": [{" + + ErrorPolicyString.builder() + .setErrorType("IKE_PROTOCOL_ERROR_TYPE") + .setErrorDetails(List.of("24")) + .setRetryArray(List.of("100")) + .setUnthrottlingEvents( + List.of("APM_ENABLE_EVENT", "WIFI_AP_CHANGED_EVENT")) + .build() + .getErrorPolicyInString() + + "}]" + + "}]"; + + PersistableBundle bundle = new PersistableBundle(); + bundle.putString(ErrorPolicyManager.KEY_ERROR_POLICY_CONFIG_STRING, config); + setupMockForCarrierConfigWithCarrierId(bundle, 1 /* carrierId */); + mErrorPolicyManager + .mHandler + .obtainMessage(IwlanEventListener.CARRIER_CONFIG_CHANGED_EVENT) + .sendToTarget(); + mTestLooper.dispatchAll(); + + // IKE_PROTOCOL_ERROR_TYPE(24) and retry time = 100. + IwlanError iwlanError = buildIwlanIkeAuthFailedError(); + long time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); + assertEquals(100, time); + + bundle.putString(ErrorPolicyManager.KEY_ERROR_POLICY_CONFIG_STRING, null); + setupMockForCarrierConfigWithCarrierId(bundle, 2 /* carrierId */); + mErrorPolicyManager + .mHandler + .obtainMessage(IwlanEventListener.CARRIER_CONFIG_CHANGED_EVENT) + .sendToTarget(); + mTestLooper.dispatchAll(); + + // IKE_PROTOCOL_ERROR_TYPE(24). Fall back to default error policy, retry time = 5. + time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); + assertEquals(5, time); + } + + @Test public void testCanBringUpTunnel() throws Exception { String apn = "ims"; String config = @@ -1061,6 +1108,10 @@ public class ErrorPolicyManagerTest { } private void setupMockForCarrierConfig(PersistableBundle bundle) { + setupMockForCarrierConfigWithCarrierId(bundle, TEST_CARRIER_ID); + } + + private void setupMockForCarrierConfigWithCarrierId(PersistableBundle bundle, int carrierId) { doReturn(mMockCarrierConfigManager) .when(mMockContext) .getSystemService(eq(CarrierConfigManager.class)); @@ -1071,7 +1122,7 @@ public class ErrorPolicyManagerTest { doReturn(mMockTelephonyManager) .when(mMockTelephonyManager) .createForSubscriptionId(anyInt()); - doReturn(TEST_CARRIER_ID).when(mMockTelephonyManager).getSimCarrierId(); + doReturn(carrierId).when(mMockTelephonyManager).getSimCarrierId(); SubscriptionInfo mockSubInfo = mock(SubscriptionInfo.class); doReturn(mockSubInfo) .when(mMockSubscriptionManager) |