summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSewook Seo <sewookseo@google.com>2023-02-24 00:08:58 +0000
committerSewook Seo <sewookseo@google.com>2023-02-27 13:34:00 +0000
commit3518eece2811eeb75fc13a7fc28002587d4e5ff0 (patch)
tree26d2556432d5789b6465f7a083cab4b25247d3f0
parent9dc314f1e62cc381cd38f3ad4d8f5651a32ca9d7 (diff)
downloadTelephony-3518eece2811eeb75fc13a7fc28002587d4e5ff0.tar.gz
[QNS] use type 'long' for throttling time
Handling throttling time with type 'long'. Bug: 267612616 Test: atest QualifiedNetworksServiceTest Change-Id: I49f92530e51ae92b216340184b92d7b327acd6e2 (cherry picked from commit 6e1d7db2c9397c1b9551005ab31096631590784e)
-rw-r--r--services/QualifiedNetworksService/src/com/android/telephony/qns/RestrictManager.java32
-rw-r--r--services/QualifiedNetworksService/tests/src/com/android/telephony/qns/RestrictManagerTest.java69
2 files changed, 93 insertions, 8 deletions
diff --git a/services/QualifiedNetworksService/src/com/android/telephony/qns/RestrictManager.java b/services/QualifiedNetworksService/src/com/android/telephony/qns/RestrictManager.java
index beb316b..9ae8a1d 100644
--- a/services/QualifiedNetworksService/src/com/android/telephony/qns/RestrictManager.java
+++ b/services/QualifiedNetworksService/src/com/android/telephony/qns/RestrictManager.java
@@ -325,12 +325,15 @@ class RestrictManager {
final ArrayList<Integer> mReleaseEventList;
long mReleaseTime;
- Restriction(int type, int[] releaseEvents, int restrictTime) {
+ Restriction(int type, int[] releaseEvents, long restrictTime) {
mRestrictType = type;
if (restrictTime == 0) {
mReleaseTime = 0;
} else {
mReleaseTime = restrictTime + SystemClock.elapsedRealtime();
+ if (restrictTime > 0 && mReleaseTime < 0) {
+ mReleaseTime = Long.MAX_VALUE;
+ }
}
if (releaseEvents != null && releaseEvents.length > 0) {
mReleaseEventList = new ArrayList<>();
@@ -354,8 +357,11 @@ class RestrictManager {
return false;
}
- void updateRestrictTime(int timeMillis) {
+ void updateRestrictTime(long timeMillis) {
mReleaseTime = SystemClock.elapsedRealtime() + timeMillis;
+ if (timeMillis > 0 && mReleaseTime < 0) {
+ mReleaseTime = Long.MAX_VALUE;
+ }
}
@Override
@@ -788,7 +794,7 @@ class RestrictManager {
mDeferredThrottlingEvent.first,
RESTRICT_TYPE_THROTTLING,
sReleaseEventMap.get(RESTRICT_TYPE_THROTTLING),
- (int) delayMillis);
+ delayMillis);
}
mDeferredThrottlingEvent = null;
}
@@ -1173,7 +1179,7 @@ class RestrictManager {
}
}
- void addRestriction(int transport, Restriction restrictObj, int timeMillis) {
+ void addRestriction(int transport, Restriction restrictObj, long timeMillis) {
boolean needNotify = false;
HashMap<Integer, Restriction> restrictionMap =
mRestrictInfos.get(transport).getRestrictionMap();
@@ -1185,7 +1191,8 @@ class RestrictManager {
+ "] "
+ restrictTypeToString(restrictObj.mRestrictType)
+ " was restrict:"
- + (restriction != null));
+ + (restriction != null)
+ + " timeMillis:" + timeMillis);
if (restriction == null) {
restriction = restrictObj;
restrictionMap.put(restrictObj.mRestrictType, restriction);
@@ -1216,7 +1223,7 @@ class RestrictManager {
}
}
- void addRestriction(int transport, int type, int[] releaseEvents, int timeMillis) {
+ void addRestriction(int transport, int type, int[] releaseEvents, long timeMillis) {
boolean needNotify = false;
HashMap<Integer, Restriction> restrictionMap =
mRestrictInfos.get(transport).getRestrictionMap();
@@ -1228,7 +1235,8 @@ class RestrictManager {
+ "] "
+ restrictTypeToString(type)
+ " was restrict:"
- + (restriction != null));
+ + (restriction != null)
+ + " timeMillis:" + timeMillis);
if (restriction == null) {
restriction = new Restriction(type, releaseEvents, timeMillis);
restrictionMap.put(type, restriction);
@@ -1579,6 +1587,10 @@ class RestrictManager {
+ " transportType:"
+ QnsConstants.transportTypeToString(transportType));
if (throttle) {
+ if (throttleTime < 0) {
+ //FWK send minus value of throttle expiration time, consider anomaly report at here.
+ return;
+ }
long delayMillis = throttleTime - SystemClock.elapsedRealtime();
if (delayMillis > 0) {
if (mDataConnectionStatusTracker.isActiveState()) {
@@ -1590,11 +1602,15 @@ class RestrictManager {
+ throttleTime);
mDeferredThrottlingEvent = new Pair<>(transportType, throttleTime);
} else {
+ if (throttleTime == Long.MAX_VALUE || throttleTime == Integer.MAX_VALUE) {
+ //Keep throttle status until receiving un-throttle event.
+ delayMillis = 0;
+ }
addRestriction(
transportType,
RESTRICT_TYPE_THROTTLING,
sReleaseEventMap.get(RESTRICT_TYPE_THROTTLING),
- (int) delayMillis);
+ delayMillis);
}
}
} else {
diff --git a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/RestrictManagerTest.java b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/RestrictManagerTest.java
index 68f0adf..466e687 100644
--- a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/RestrictManagerTest.java
+++ b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/RestrictManagerTest.java
@@ -932,6 +932,75 @@ public class RestrictManagerTest extends QnsTest {
}
@Test
+ public void testRestrictWithThrottlingWithThrottleTimeMax() {
+ long throttleTime = Long.MAX_VALUE;
+ mRestrictManager.notifyThrottling(
+ true, throttleTime, AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
+ assertTrue(
+ mRestrictManager.hasRestrictionType(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING));
+ long elapsed = SystemClock.elapsedRealtime();
+ mTestLooper.moveTimeForward(Long.MAX_VALUE - elapsed);
+ mTestLooper.dispatchAll();
+ mTestLooper.moveTimeForward(Long.MAX_VALUE - elapsed);
+ mTestLooper.dispatchAll();
+ assertTrue(
+ mRestrictManager.hasRestrictionType(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING));
+ mRestrictManager.releaseRestriction(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING);
+ assertFalse(
+ mRestrictManager.hasRestrictionType(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING));
+
+ throttleTime = Integer.MAX_VALUE;
+ mRestrictManager.notifyThrottling(
+ true, throttleTime, AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
+ assertTrue(
+ mRestrictManager.hasRestrictionType(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING));
+ elapsed = SystemClock.elapsedRealtime();
+ mTestLooper.moveTimeForward(Long.MAX_VALUE - elapsed);
+ mTestLooper.dispatchAll();
+ assertTrue(
+ mRestrictManager.hasRestrictionType(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING));
+ mRestrictManager.releaseRestriction(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING);
+ assertFalse(
+ mRestrictManager.hasRestrictionType(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING));
+ }
+
+ @Test
+ public void testRestrictWithThrottlingWithAbnormalThrottleTime() {
+ long throttleTime = -134243;
+ mRestrictManager.notifyThrottling(
+ true, throttleTime, AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
+ assertFalse(
+ mRestrictManager.hasRestrictionType(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING));
+
+ throttleTime = Long.MAX_VALUE - 100;
+ mRestrictManager.notifyThrottling(
+ true, throttleTime, AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
+ assertTrue(
+ mRestrictManager.hasRestrictionType(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING));
+ long elapsed = SystemClock.elapsedRealtime();
+ mTestLooper.moveTimeForward(Long.MAX_VALUE - elapsed * 2);
+ mTestLooper.dispatchAll();
+ assertTrue(
+ mRestrictManager.hasRestrictionType(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING));
+ mTestLooper.moveTimeForward(elapsed + 1000);
+ mTestLooper.dispatchAll();
+ assertFalse(
+ mRestrictManager.hasRestrictionType(
+ AccessNetworkConstants.TRANSPORT_TYPE_WLAN, RESTRICT_TYPE_THROTTLING));
+ }
+
+ @Test
public void testDeferThrottlingDuringActiveState() {
long throttleTime = SystemClock.elapsedRealtime() + 10000;
DataConnectionStatusTracker.DataConnectionChangedInfo dcInfo =