summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-13 23:21:08 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-13 23:21:08 +0000
commit73eecb8d81d6f569f493728b85dd3d927dd4dda8 (patch)
treef521bd08a6f0e627c2c177a41a6230e444f35329
parent736a4b2aa8025a0baba1c29fe548be65df75e2d0 (diff)
parent3f5724ffd1257bbd5d529a56ccdff18413f8d682 (diff)
downloadIwlan-73eecb8d81d6f569f493728b85dd3d927dd4dda8.tar.gz
Snap for 10492621 from 3f5724ffd1257bbd5d529a56ccdff18413f8d682 to udc-qpr1-release
Change-Id: Ie9bd44f3b0115e278ff4d35b48eec7cb4644b6e6
-rw-r--r--src/com/google/android/iwlan/ErrorPolicyManager.java15
-rw-r--r--src/com/google/android/iwlan/IwlanEventListener.java8
-rw-r--r--test/com/google/android/iwlan/ErrorPolicyManagerTest.java53
-rw-r--r--test/com/google/android/iwlan/IwlanEventListenerTest.java33
4 files changed, 97 insertions, 12 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/src/com/google/android/iwlan/IwlanEventListener.java b/src/com/google/android/iwlan/IwlanEventListener.java
index f76c179..bcc6ca7 100644
--- a/src/com/google/android/iwlan/IwlanEventListener.java
+++ b/src/com/google/android/iwlan/IwlanEventListener.java
@@ -168,11 +168,9 @@ public class IwlanEventListener {
LOG_TAG,
"Call state changed to " + callStateToString(state) + " for slot " + mSlotId);
- for (Map.Entry<Integer, IwlanEventListener> entry : mInstances.entrySet()) {
- IwlanEventListener instance = entry.getValue();
- if (instance != null) {
- instance.updateHandlers(CALL_STATE_CHANGED_EVENT, state);
- }
+ IwlanEventListener instance = mInstances.get(mSlotId);
+ if (instance != null) {
+ instance.updateHandlers(CALL_STATE_CHANGED_EVENT, state);
}
}
}
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)
diff --git a/test/com/google/android/iwlan/IwlanEventListenerTest.java b/test/com/google/android/iwlan/IwlanEventListenerTest.java
index 79d53c0..81a0bbf 100644
--- a/test/com/google/android/iwlan/IwlanEventListenerTest.java
+++ b/test/com/google/android/iwlan/IwlanEventListenerTest.java
@@ -63,6 +63,7 @@ public class IwlanEventListenerTest {
@Mock private TelephonyManager mMockTelephonyManager;
private static final int DEFAULT_SLOT_INDEX = 0;
+ private static final int OTHER_SLOT_INDEX = 1;
private static final int DEFAULT_CARRIER_INDEX = 0;
private static final String WIFI_SSID_1 = "TEST_AP_NAME_1";
private static final String WIFI_SSID_2 = "TEST_AP_NAME_2";
@@ -303,6 +304,38 @@ public class IwlanEventListenerTest {
}
@Test
+ public void testCallStateChangedMultipleSlots() throws Exception {
+ IwlanEventListener otherSlotIwlanEventListener =
+ IwlanEventListener.getInstance(mMockContext, OTHER_SLOT_INDEX);
+
+ when(mMockHandler.obtainMessage(
+ eq(IwlanEventListener.CALL_STATE_CHANGED_EVENT),
+ eq(DEFAULT_SLOT_INDEX),
+ eq(TelephonyManager.CALL_STATE_OFFHOOK)))
+ .thenReturn(mMockMessage);
+ when(mMockHandler.obtainMessage(
+ eq(IwlanEventListener.CALL_STATE_CHANGED_EVENT),
+ eq(OTHER_SLOT_INDEX),
+ eq(TelephonyManager.CALL_STATE_OFFHOOK)))
+ .thenReturn(mMockMessage_2);
+
+ events = new ArrayList<Integer>();
+ events.add(IwlanEventListener.CALL_STATE_CHANGED_EVENT);
+ mIwlanEventListener.addEventListener(events, mMockHandler);
+ otherSlotIwlanEventListener.addEventListener(events, mMockHandler);
+
+ mIwlanEventListener.registerTelephonyCallback();
+ otherSlotIwlanEventListener.registerTelephonyCallback();
+
+ TelephonyCallback.CallStateListener mTelephonyCallback =
+ mIwlanEventListener.getTelephonyCallback();
+ mTelephonyCallback.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK);
+
+ verify(mMockMessage, times(1)).sendToTarget();
+ verify(mMockMessage_2, never()).sendToTarget();
+ }
+
+ @Test
public void testWfcChangeThrowIAE() throws Exception {
when(mMockHandler.obtainMessage(
eq(IwlanEventListener.WIFI_CALLING_DISABLE_EVENT),