summaryrefslogtreecommitdiff
path: root/test/com/google/android
diff options
context:
space:
mode:
authorKuen Yuet Cheung <kuenyuet@google.com>2023-11-08 09:09:31 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-11-08 09:09:31 +0000
commit7652db595efcd53504359a6ed9bb30e84c31a9f8 (patch)
treed9ab070fa0321878d805eaccd5bb0255434d5920 /test/com/google/android
parentc8bfe59506bcdbeb566a964f183d047b2d45464c (diff)
parentbd1a2d7500f5b99778863574f6d965653b5bdb12 (diff)
downloadIwlan-7652db595efcd53504359a6ed9bb30e84c31a9f8.tar.gz
Merge changes I708e186b,I552a76b7 into main
* changes: Refactor ErrorInfo in ErrorPolicyManager Fix findErrorPolicy cannot ensure result not null
Diffstat (limited to 'test/com/google/android')
-rw-r--r--test/com/google/android/iwlan/ErrorPolicyManagerTest.java48
-rw-r--r--test/com/google/android/iwlan/IwlanDataServiceTest.java14
2 files changed, 51 insertions, 11 deletions
diff --git a/test/com/google/android/iwlan/ErrorPolicyManagerTest.java b/test/com/google/android/iwlan/ErrorPolicyManagerTest.java
index 8732e42..1dd1926 100644
--- a/test/com/google/android/iwlan/ErrorPolicyManagerTest.java
+++ b/test/com/google/android/iwlan/ErrorPolicyManagerTest.java
@@ -52,7 +52,9 @@ import org.mockito.MockitoAnnotations;
import org.mockito.MockitoSession;
import org.mockito.quality.Strictness;
+import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -818,10 +820,10 @@ public class ErrorPolicyManagerTest {
assertEquals(DataFailCause.IWLAN_PDN_CONNECTION_REJECTION, failCause);
long retryTime =
- Math.round((double) mErrorPolicyManager.getCurrentRetryTimeMs(apn1) / 1000);
+ Math.round((double) mErrorPolicyManager.getRemainingRetryTimeMs(apn1) / 1000);
assertEquals(4, retryTime);
- retryTime = Math.round((double) mErrorPolicyManager.getCurrentRetryTimeMs(apn2) / 1000);
+ retryTime = Math.round((double) mErrorPolicyManager.getRemainingRetryTimeMs(apn2) / 1000);
assertEquals(5, retryTime);
}
@@ -866,7 +868,7 @@ public class ErrorPolicyManagerTest {
IwlanError iwlanError = buildIwlanIkeAuthFailedError();
long time = mErrorPolicyManager.reportIwlanError(apn, iwlanError, 2);
- time = Math.round((double) mErrorPolicyManager.getCurrentRetryTimeMs(apn) / 1000);
+ time = Math.round((double) mErrorPolicyManager.getRemainingRetryTimeMs(apn) / 1000);
assertEquals(time, 2);
// advanceClockByTimeMs for 2 seconds and make sure that we can bring up tunnel after 2 secs
@@ -883,7 +885,7 @@ public class ErrorPolicyManagerTest {
assertFalse(bringUpTunnel);
time = mErrorPolicyManager.reportIwlanError(apn, iwlanError, 5);
- time = Math.round((double) mErrorPolicyManager.getCurrentRetryTimeMs(apn) / 1000);
+ time = Math.round((double) mErrorPolicyManager.getRemainingRetryTimeMs(apn) / 1000);
assertEquals(time, 5);
// test whether the same error reported later starts from the beginning of retry array
@@ -1138,6 +1140,44 @@ public class ErrorPolicyManagerTest {
mTestLooper.dispatchAll();
}
+ @Test
+ public void testShouldNotThrowWhenDefaultConfigInvalid() throws Exception {
+ String apn = "ims";
+ AssetManager mockAssetManager = mock(AssetManager.class);
+ doReturn(mockAssetManager).when(mMockContext).getAssets();
+
+ // when the default config do not match all error with "ErrorType": "*"
+ String defaultConfigErrorTypeJson =
+ "{\"ErrorType\": \"IKE_PROTOCOL_ERROR_TYPE\", \"ErrorDetails\": [\"*\"], "
+ + "\"RetryArray\": [\"0\"], \"UnthrottlingEvents\": []}";
+ String defaultConfigJson =
+ "[{\"ApnName\": \"*\", \"ErrorTypes\": [" + defaultConfigErrorTypeJson + "]}]";
+ InputStream defaultConfigInputStream =
+ new ByteArrayInputStream(defaultConfigJson.getBytes(StandardCharsets.UTF_8));
+ doReturn(defaultConfigInputStream).when(mockAssetManager).open(any());
+ PersistableBundle bundle = new PersistableBundle();
+
+ // need to reconstruct error policy manager with the mocked default config
+ mErrorPolicyManager.releaseInstance();
+ mErrorPolicyManager = spy(ErrorPolicyManager.getInstance(mMockContext, DEFAULT_SLOT_INDEX));
+ doReturn(mTestLooper.getLooper()).when(mErrorPolicyManager).getLooper();
+ mErrorPolicyManager.initHandler();
+
+ bundle.putString(ErrorPolicyManager.KEY_ERROR_POLICY_CONFIG_STRING, null);
+ setupMockForCarrierConfig(bundle);
+
+ mErrorPolicyManager
+ .mHandler
+ .obtainMessage(IwlanEventListener.CARRIER_CONFIG_CHANGED_EVENT)
+ .sendToTarget();
+ mTestLooper.dispatchAll();
+
+ // if some error happen and no policy in carrier config match, and the default config do
+ // not have at least 1 policy can apply to all error, it should not throw error
+ IwlanError iwlanError = new IwlanError(IwlanError.EPDG_SELECTOR_SERVER_SELECTION_FAILED);
+ mErrorPolicyManager.reportIwlanError(apn, iwlanError);
+ }
+
private void setupMockForCarrierConfig(PersistableBundle bundle) {
setupMockForCarrierConfigWithCarrierId(bundle, TEST_CARRIER_ID);
}
diff --git a/test/com/google/android/iwlan/IwlanDataServiceTest.java b/test/com/google/android/iwlan/IwlanDataServiceTest.java
index 09d8cb9..e7dc34d 100644
--- a/test/com/google/android/iwlan/IwlanDataServiceTest.java
+++ b/test/com/google/android/iwlan/IwlanDataServiceTest.java
@@ -67,8 +67,8 @@ import android.telephony.data.DataCallResponse;
import android.telephony.data.DataProfile;
import android.telephony.data.DataService;
import android.telephony.data.DataServiceCallback;
-import android.telephony.data.NetworkSliceInfo;
import android.telephony.data.IDataServiceCallback;
+import android.telephony.data.NetworkSliceInfo;
import android.telephony.ims.ImsManager;
import android.telephony.ims.ImsMmTelManager;
@@ -871,7 +871,7 @@ public class IwlanDataServiceTest {
when(ErrorPolicyManager.getInstance(eq(mMockContext), eq(DEFAULT_SLOT_INDEX)))
.thenReturn(mMockErrorPolicyManager);
- when(mMockErrorPolicyManager.getCurrentRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(5L);
+ when(mMockErrorPolicyManager.getRemainingRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(5L);
when(mMockErrorPolicyManager.getDataFailCause(eq(TEST_APN_NAME)))
.thenReturn(DataFailCause.USER_AUTHENTICATION);
@@ -921,7 +921,7 @@ public class IwlanDataServiceTest {
when(ErrorPolicyManager.getInstance(eq(mMockContext), eq(DEFAULT_SLOT_INDEX)))
.thenReturn(mMockErrorPolicyManager);
- when(mMockErrorPolicyManager.getCurrentRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(-1L);
+ when(mMockErrorPolicyManager.getRemainingRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(-1L);
when(mMockErrorPolicyManager.getDataFailCause(eq(TEST_APN_NAME)))
.thenReturn(DataFailCause.ERROR_UNSPECIFIED);
when(mMockErrorPolicyManager.shouldRetryWithInitialAttach(eq(TEST_APN_NAME)))
@@ -973,7 +973,7 @@ public class IwlanDataServiceTest {
when(ErrorPolicyManager.getInstance(eq(mMockContext), eq(DEFAULT_SLOT_INDEX)))
.thenReturn(mMockErrorPolicyManager);
- when(mMockErrorPolicyManager.getCurrentRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(-1L);
+ when(mMockErrorPolicyManager.getRemainingRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(-1L);
when(mMockErrorPolicyManager.getDataFailCause(eq(TEST_APN_NAME)))
.thenReturn(DataFailCause.ERROR_UNSPECIFIED);
when(mMockErrorPolicyManager.shouldRetryWithInitialAttach(eq(TEST_APN_NAME)))
@@ -1031,7 +1031,7 @@ public class IwlanDataServiceTest {
when(ErrorPolicyManager.getInstance(eq(mMockContext), eq(DEFAULT_SLOT_INDEX)))
.thenReturn(mMockErrorPolicyManager);
- when(mMockErrorPolicyManager.getCurrentRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(-1L);
+ when(mMockErrorPolicyManager.getRemainingRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(-1L);
when(mMockErrorPolicyManager.getDataFailCause(eq(TEST_APN_NAME)))
.thenReturn(DataFailCause.ERROR_UNSPECIFIED);
when(mMockErrorPolicyManager.shouldRetryWithInitialAttach(eq(TEST_APN_NAME)))
@@ -1089,7 +1089,7 @@ public class IwlanDataServiceTest {
when(ErrorPolicyManager.getInstance(eq(mMockContext), eq(DEFAULT_SLOT_INDEX)))
.thenReturn(mMockErrorPolicyManager);
- when(mMockErrorPolicyManager.getCurrentRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(-1L);
+ when(mMockErrorPolicyManager.getRemainingRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(-1L);
when(mMockErrorPolicyManager.getDataFailCause(eq(TEST_APN_NAME)))
.thenReturn(DataFailCause.ERROR_UNSPECIFIED);
when(mMockErrorPolicyManager.shouldRetryWithInitialAttach(eq(TEST_APN_NAME)))
@@ -1147,7 +1147,7 @@ public class IwlanDataServiceTest {
when(ErrorPolicyManager.getInstance(eq(mMockContext), eq(DEFAULT_SLOT_INDEX)))
.thenReturn(mMockErrorPolicyManager);
- when(mMockErrorPolicyManager.getCurrentRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(-1L);
+ when(mMockErrorPolicyManager.getRemainingRetryTimeMs(eq(TEST_APN_NAME))).thenReturn(-1L);
when(mMockErrorPolicyManager.getDataFailCause(eq(TEST_APN_NAME)))
.thenReturn(DataFailCause.ERROR_UNSPECIFIED);
when(mMockErrorPolicyManager.shouldRetryWithInitialAttach(eq(TEST_APN_NAME)))