From 4b6d12aca9660b9ef84ab4cb0e39b620b556a693 Mon Sep 17 00:00:00 2001 From: Kuen Yuet Cheung Date: Fri, 15 Sep 2023 18:06:09 +0800 Subject: Keep the RetryIndex if the Error is IKE Protocol Exception Test: atest Bug: 292312000 Change-Id: I722f543de2ab6ce94410c7be1ce58528ae762626 --- .../google/android/iwlan/ErrorPolicyManager.java | 18 +++++++++ .../android/iwlan/ErrorPolicyManagerTest.java | 47 ++++++++++++++++++---- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/com/google/android/iwlan/ErrorPolicyManager.java b/src/com/google/android/iwlan/ErrorPolicyManager.java index 53a032c..d6b7c39 100644 --- a/src/com/google/android/iwlan/ErrorPolicyManager.java +++ b/src/com/google/android/iwlan/ErrorPolicyManager.java @@ -219,6 +219,16 @@ public class ErrorPolicyManager { Log.d(LOG_TAG, "Doesn't match to the previous error" + iwlanError); ErrorPolicy policy = findErrorPolicy(apn, iwlanError); ErrorInfo errorInfo = new ErrorInfo(iwlanError, policy); + if (mLastErrorForApn.containsKey(apn)) { + ErrorInfo prevErrorInfo = mLastErrorForApn.get(apn); + IwlanError prevIwlanError = prevErrorInfo.getError(); + // If prev and current error are both IKE_PROTOCOL_EXCEPTION, keep the retry index + // TODO: b/292312000 - Workaround for RetryIndex lost + if (iwlanError.getErrorType() == IwlanError.IKE_PROTOCOL_EXCEPTION + && prevIwlanError.getErrorType() == IwlanError.IKE_PROTOCOL_EXCEPTION) { + errorInfo.setCurrentRetryIndex(prevErrorInfo.getCurrentRetryIndex()); + } + } mLastErrorForApn.put(apn, errorInfo); } retryTime = mLastErrorForApn.get(apn).updateCurrentRetryTime(); @@ -1076,6 +1086,14 @@ public class ErrorPolicyManager { mLastErrorTime = IwlanHelper.elapsedRealtime(); } + int getCurrentRetryIndex() { + return mCurrentRetryIndex; + } + + void setCurrentRetryIndex(int currentRetryIndex) { + mCurrentRetryIndex = currentRetryIndex; + } + /** * Updates the current retry index and returns the retry time at new index position and also * updates mLastErrorTime to current time. returns -1 if the index is out of bounds diff --git a/test/com/google/android/iwlan/ErrorPolicyManagerTest.java b/test/com/google/android/iwlan/ErrorPolicyManagerTest.java index f9ec9fa..8732e42 100644 --- a/test/com/google/android/iwlan/ErrorPolicyManagerTest.java +++ b/test/com/google/android/iwlan/ErrorPolicyManagerTest.java @@ -244,18 +244,13 @@ public class ErrorPolicyManagerTest { assertEquals(4, time); time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); assertEquals(8, time); - time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); - assertEquals(16, time); - time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); - assertEquals(86400, time); // Validate the range error detail. + // TODO: b/292312000 - IKE Protocol Error Keep RetryIndex Workaround + // IKE Protocol Error will keep the RetryIndex. Although a new error with + // different error code reported, timer will not start at RetryIndex 0 iwlanError = buildIwlanIkeProtocolError(9030, new byte[] {0x00, 0x01}); time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); - assertEquals(4, time); - time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); - assertEquals(8, time); - time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); assertEquals(16, time); time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); assertEquals(86400, time); @@ -269,6 +264,18 @@ public class ErrorPolicyManagerTest { time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); assertEquals(86400, time); + // Fallback case IKE_INIT_TIMEOUT and retryArray is 1, 2, 2, 10, 20 + // Should start at RetryIndex 0 + iwlanError = new IwlanError(IwlanError.IKE_INIT_TIMEOUT); + time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); + assertEquals(1, time); + time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); + assertEquals(2, time); + time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); + assertEquals(2, time); + time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); + assertEquals(10, time); + // Fallback case GENERIC_PROTOCOL_ERROR_TYPE(44) and retryArray is 5, 10, -1 as in // DEFAULT_CONFIG iwlanError = buildIwlanIkeChildSaNotFoundError(); @@ -327,6 +334,14 @@ public class ErrorPolicyManagerTest { time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); assertEquals(80, time); + // TODO: b/292312000 - IKE Protocol Error Keep RetryIndex Workaround + // Use APM_ENABLE_EVENT to reset the RetryIndex + mErrorPolicyManager + .mHandler + .obtainMessage(IwlanEventListener.APM_ENABLE_EVENT) + .sendToTarget(); + mTestLooper.dispatchAll(); + iwlanError = buildIwlanIkeProtocolError(9002); time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); assertEquals(5, time); @@ -341,6 +356,14 @@ public class ErrorPolicyManagerTest { time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); assertEquals(80, time); + // TODO: b/292312000 - IKE Protocol Error Keep RetryIndex Workaround + // Use APM_ENABLE_EVENT to reset the RetryIndex + mErrorPolicyManager + .mHandler + .obtainMessage(IwlanEventListener.APM_ENABLE_EVENT) + .sendToTarget(); + mTestLooper.dispatchAll(); + iwlanError = buildIwlanIkeInternalAddressFailure(); time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); assertEquals(0, time); @@ -401,6 +424,14 @@ public class ErrorPolicyManagerTest { time = mErrorPolicyManager.reportIwlanError(apn, iwlanError); assertEquals(86400, time); + // TODO: b/292312000 - IKE Protocol Error Keep RetryIndex Workaround + // Use APM_ENABLE_EVENT to reset the RetryIndex + mErrorPolicyManager + .mHandler + .obtainMessage(IwlanEventListener.APM_ENABLE_EVENT) + .sendToTarget(); + mTestLooper.dispatchAll(); + // IKE_PROTOCOL_ERROR_TYPE(44) and retryArray = 0 as it will fallback to // IKE_PROTOCOL_ERROR_TYPE generic fallback first. iwlanError = buildIwlanIkeChildSaNotFoundError(); -- cgit v1.2.3