diff options
author | sangyun <sangyun@google.com> | 2023-02-14 11:17:44 +0900 |
---|---|---|
committer | sangyun <sangyun@google.com> | 2023-03-13 10:07:20 +0900 |
commit | 91bd6a427da8d68f5faf80a2dae6610a7ddeb016 (patch) | |
tree | 5b3b933ab819eae3756948962122d837d1134eb5 | |
parent | 9682fd04f42572a536cdebecd5bc0664524a639e (diff) | |
download | Telephony-91bd6a427da8d68f5faf80a2dae6610a7ddeb016.tar.gz |
[QNS] Stop monitoring thresholds for EIMS when data disconnected.
- When cellular is unavailable, CellularQuailtyMonitor will clear
requests to telephonyCallBack.
- When cellular become available again, other APns will reset the
threshold by calling unregisterThresholdToQualityMonitor. For
Emergency, according to current design, in some case, the
threshold will not be reset as QNS only handles HO of Emergency
data connection.
- In result, CellularQuailtyMonitor will not listen to
telephonyCallBack, until the set of threshold values is changed.
Bug: 268269409
Test: atest QualifiedNetworksServiceTests
Change-Id: I309be73d2fa6039ca97a79eb12e502fdb0e482c0
Signed-off-by: Jeremy Chow <ktchow@google.com>
2 files changed, 84 insertions, 5 deletions
diff --git a/services/QualifiedNetworksService/src/com/android/telephony/qns/AccessNetworkEvaluator.java b/services/QualifiedNetworksService/src/com/android/telephony/qns/AccessNetworkEvaluator.java index ae1a32d..46405b7 100644 --- a/services/QualifiedNetworksService/src/com/android/telephony/qns/AccessNetworkEvaluator.java +++ b/services/QualifiedNetworksService/src/com/android/telephony/qns/AccessNetworkEvaluator.java @@ -63,6 +63,10 @@ class AccessNetworkEvaluator { private static final int EVENT_SIP_DIALOG_SESSION_STATE_CHANGED = EVENT_BASE + 12; private static final int EVALUATE_SPECIFIC_REASON_NONE = 0; private static final int EVALUATE_SPECIFIC_REASON_IWLAN_DISABLE = 1; + private static final int EVALUATE_SPECIFIC_REASON_DATA_DISCONNECTED = 2; + private static final int EVALUATE_SPECIFIC_REASON_DATA_FAILED = 3; + private static final int EVALUATE_SPECIFIC_REASON_DATA_CONNECTED = 4; + protected final int mSlotIndex; protected final Context mContext; private final String mLogTag; @@ -708,32 +712,50 @@ class AccessNetworkEvaluator { DataConnectionStatusTracker.DataConnectionChangedInfo info) { log("onDataConnectionStateChanged info:" + info); boolean needEvaluate = false; + int evaluateSpecificReason = EVALUATE_SPECIFIC_REASON_NONE; switch (info.getEvent()) { case DataConnectionStatusTracker.EVENT_DATA_CONNECTION_DISCONNECTED: + evaluateSpecificReason = EVALUATE_SPECIFIC_REASON_DATA_DISCONNECTED; if (mNetCapability == NetworkCapabilities.NET_CAPABILITY_EIMS) { // If FWK guided emergency's transport type during data connected state, notify // the transport type when the data connection is disconnected. notifyCachedTransportTypeForEmergency(); + // When cellular is not available, CellularQualityMonitor will stop listening to + // TelephonyCallback. Thresholds for Emergency apn may not be reset as ANE for + // emergency only evaluates while data is connected. CellularQualityMonitor will + // not listen to TelephonyCallback again until the set of threshold values + // changed. Resetting thresholds for emergency after the emergency connection + // disconnects. + unregisterThresholdToQualityMonitor(); } else { needEvaluate = true; initLastNotifiedQualifiedNetwork(); } break; case DataConnectionStatusTracker.EVENT_DATA_CONNECTION_CONNECTED: + evaluateSpecificReason = EVALUATE_SPECIFIC_REASON_DATA_CONNECTED; mHandler.post(() -> onDataConnectionConnected(info.getTransportType())); break; case DataConnectionStatusTracker.EVENT_DATA_CONNECTION_FAILED: + evaluateSpecificReason = EVALUATE_SPECIFIC_REASON_DATA_FAILED; if (mNetCapability == NetworkCapabilities.NET_CAPABILITY_EIMS) { // If FWK guided emergency's transport type during data connecting state, notify // the transport type when the data connection is failed. notifyCachedTransportTypeForEmergency(); + // When cellular is not available, CellularQualityMonitor will stop listening to + // TelephonyCallback. Thresholds for Emergency apn may not be reset as ANE for + // emergency only evaluates while data is connected. CellularQualityMonitor will + // not listen to TelephonyCallback again until the set of threshold values + // changed. Resetting thresholds for emergency after the emergency connection + // disconnects. + unregisterThresholdToQualityMonitor(); } else { needEvaluate = true; } break; } if (needEvaluate) { - evaluate(); + evaluate(evaluateSpecificReason); } } @@ -1173,10 +1195,11 @@ class AccessNetworkEvaluator { return; } log("evaluate reason:" + evaluateSpecificReasonToString(specificReason)); - if (mNetCapability == NetworkCapabilities.NET_CAPABILITY_EIMS - && !mDataConnectionStatusTracker.isActiveState()) { - log("QNS only handles HO of EMERGENCY data connection"); - return; + if (mNetCapability == NetworkCapabilities.NET_CAPABILITY_EIMS) { + if (!mDataConnectionStatusTracker.isActiveState()) { + log("QNS only handles HO of EMERGENCY data connection"); + return; + } } /* Check handover policy */ @@ -1875,6 +1898,12 @@ class AccessNetworkEvaluator { return "EVALUATE_SPECIFIC_REASON_NONE"; } else if (specificReason == EVALUATE_SPECIFIC_REASON_IWLAN_DISABLE) { return "EVALUATE_SPECIFIC_REASON_IWLAN_DISABLE"; + } else if (specificReason == EVALUATE_SPECIFIC_REASON_DATA_DISCONNECTED) { + return "EVALUATE_SPECIFIC_REASON_DATA_DISCONNECTED"; + } else if (specificReason == EVALUATE_SPECIFIC_REASON_DATA_FAILED) { + return "EVALUATE_SPECIFIC_REASON_DATA_FAILED"; + } else if (specificReason == EVALUATE_SPECIFIC_REASON_DATA_CONNECTED) { + return "EVALUATE_SPECIFIC_REASON_DATA_CONNECTED"; } return "UNKNOWN"; } diff --git a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/AccessNetworkEvaluatorTest.java b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/AccessNetworkEvaluatorTest.java index 8d3883e..9ab4d2e 100644 --- a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/AccessNetworkEvaluatorTest.java +++ b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/AccessNetworkEvaluatorTest.java @@ -63,6 +63,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.stubbing.Answer; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; @@ -71,6 +72,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.stream.IntStream; @RunWith(JUnit4.class) public class AccessNetworkEvaluatorTest extends QnsTest { @@ -1734,4 +1736,52 @@ public class AccessNetworkEvaluatorTest extends QnsTest { assertEquals( QnsConstants.CALL_TYPE_VIDEO, matchedAnsp.get(0).getPreCondition().getCallType()); } + + @Test + public void testDataConnectionDisconnectedOnSos_ResettingThresholds() { + AccessNetworkEvaluator aneSos = + new AccessNetworkEvaluator( + mQnsComponents[mSlotIndex], + NetworkCapabilities.NET_CAPABILITY_EIMS, + mRestrictManager, + mDataConnectionStatusTracker, + mSlotIndex); + aneSos.registerForQualifiedNetworksChanged(mHandler, QUALIFIED_NETWORKS_CHANGED); + waitForLastHandlerAction(aneSos.mHandler); + + aneSos.onDataConnectionStateChanged( + new DataConnectionStatusTracker.DataConnectionChangedInfo( + DataConnectionStatusTracker.EVENT_DATA_CONNECTION_DISCONNECTED, + DataConnectionStatusTracker.STATE_INACTIVE, + AccessNetworkConstants.TRANSPORT_TYPE_INVALID)); + waitForLastHandlerAction(aneSos.mHandler); + + aneSos.onDataConnectionStateChanged( + new DataConnectionStatusTracker.DataConnectionChangedInfo( + DataConnectionStatusTracker.EVENT_DATA_CONNECTION_FAILED, + DataConnectionStatusTracker.STATE_INACTIVE, + AccessNetworkConstants.TRANSPORT_TYPE_INVALID)); + waitForLastHandlerAction(aneSos.mHandler); + + verify(mMockWifiQm, times(2)).updateThresholdsForNetCapability( + NetworkCapabilities.NET_CAPABILITY_EIMS, mSlotIndex, null); + } + + @Test + public void testEvaluateSpecificReasonToString() throws Exception { + Method method = AccessNetworkEvaluator.class.getDeclaredMethod( + "evaluateSpecificReasonToString", int.class); + method.setAccessible(true); + + IntStream.rangeClosed(0, 4).forEach(i -> { + try { + assertTrue(((String) method.invoke(mAne, i)).startsWith( + "EVALUATE_SPECIFIC_REASON_")); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + }); + } } |