Merge "Simplify the burst time logic" into main
diff --git a/service-t/src/com/android/server/connectivity/mdns/QueryTaskConfig.java b/service-t/src/com/android/server/connectivity/mdns/QueryTaskConfig.java
index 10a71a2..63524a6 100644
--- a/service-t/src/com/android/server/connectivity/mdns/QueryTaskConfig.java
+++ b/service-t/src/com/android/server/connectivity/mdns/QueryTaskConfig.java
@@ -159,8 +159,7 @@
}
final int maxTimeBetweenBursts = queryMode == AGGRESSIVE_QUERY_MODE
? MAX_TIME_BETWEEN_AGGRESSIVE_BURSTS_MS : MAX_TIME_BETWEEN_ACTIVE_PASSIVE_BURSTS_MS;
- return timeBetweenBurstsInMs < maxTimeBetweenBursts
- ? Math.min(timeBetweenBurstsInMs * 2, maxTimeBetweenBursts) : timeBetweenBurstsInMs;
+ return Math.min(timeBetweenBurstsInMs * 2, maxTimeBetweenBursts);
}
/**
@@ -172,21 +171,19 @@
if (newTransactionId > UNSIGNED_SHORT_MAX_VALUE) {
newTransactionId = 1;
}
- boolean newIsFirstBurst = isFirstBurst;
+
int newQueriesPerBurst = queriesPerBurst;
int newBurstCounter = burstCounter + 1;
final boolean isFirstQueryInBurst = newBurstCounter == 1;
final boolean isLastQueryInBurst = newBurstCounter == queriesPerBurst;
+ boolean newIsFirstBurst = isFirstBurst && !isLastQueryInBurst;
if (isLastQueryInBurst) {
newBurstCounter = 0;
- if (isFirstBurst) {
- newIsFirstBurst = false;
- // In passive scan mode, sends a single burst of QUERIES_PER_BURST queries, and
- // then in each TIME_BETWEEN_BURSTS interval, sends QUERIES_PER_BURST_PASSIVE_MODE
- // queries.
- if (queryMode == PASSIVE_QUERY_MODE) {
- newQueriesPerBurst = QUERIES_PER_BURST_PASSIVE_MODE;
- }
+ // In passive scan mode, sends a single burst of QUERIES_PER_BURST queries, and
+ // then in each TIME_BETWEEN_BURSTS interval, sends QUERIES_PER_BURST_PASSIVE_MODE
+ // queries.
+ if (isFirstBurst && queryMode == PASSIVE_QUERY_MODE) {
+ newQueriesPerBurst = QUERIES_PER_BURST_PASSIVE_MODE;
}
}
diff --git a/tests/unit/java/com/android/server/connectivity/mdns/MdnsServiceTypeClientTests.java b/tests/unit/java/com/android/server/connectivity/mdns/MdnsServiceTypeClientTests.java
index df23da4..dab3b42 100644
--- a/tests/unit/java/com/android/server/connectivity/mdns/MdnsServiceTypeClientTests.java
+++ b/tests/unit/java/com/android/server/connectivity/mdns/MdnsServiceTypeClientTests.java
@@ -1777,13 +1777,6 @@
socketKey);
}
- private int getBetweenBurstTime(int burstCounter, int currentBetweenTime, int maxBetweenTime,
- int initialBetweenTime) {
- return currentBetweenTime < maxBetweenTime
- ? Math.min(initialBetweenTime * (int) Math.pow(2, burstCounter), maxBetweenTime)
- : currentBetweenTime;
- }
-
@Test
public void sendQueries_aggressiveScanMode() {
final MdnsSearchOptions searchOptions = MdnsSearchOptions.newBuilder()
@@ -1799,9 +1792,9 @@
verifyAndSendQuery(i + 1, /* timeInMs= */ 0, /* expectsUnicastResponse= */ false);
verifyAndSendQuery(i + 2, TIME_BETWEEN_RETRANSMISSION_QUERIES_IN_BURST_MS,
/* expectsUnicastResponse= */ false);
- betweenBurstTime = getBetweenBurstTime(burstCounter, betweenBurstTime,
- MAX_TIME_BETWEEN_AGGRESSIVE_BURSTS_MS,
- INITIAL_AGGRESSIVE_TIME_BETWEEN_BURSTS_MS);
+ betweenBurstTime = Math.min(
+ INITIAL_AGGRESSIVE_TIME_BETWEEN_BURSTS_MS * (int) Math.pow(2, burstCounter),
+ MAX_TIME_BETWEEN_AGGRESSIVE_BURSTS_MS);
burstCounter++;
}
// Verify that Task is not removed before stopSendAndReceive was called.
@@ -1860,9 +1853,9 @@
verifyAndSendQuery(i + 1, /* timeInMs= */ 0, /* expectsUnicastResponse= */ false);
verifyAndSendQuery(i + 2, TIME_BETWEEN_RETRANSMISSION_QUERIES_IN_BURST_MS,
/* expectsUnicastResponse= */ false);
- betweenBurstTime = getBetweenBurstTime(burstCounter, betweenBurstTime,
- MAX_TIME_BETWEEN_AGGRESSIVE_BURSTS_MS,
- INITIAL_AGGRESSIVE_TIME_BETWEEN_BURSTS_MS);
+ betweenBurstTime = Math.min(
+ INITIAL_AGGRESSIVE_TIME_BETWEEN_BURSTS_MS * (int) Math.pow(2, burstCounter),
+ MAX_TIME_BETWEEN_AGGRESSIVE_BURSTS_MS);
burstCounter++;
}
// In backoff mode, the current scheduled task will be canceled and reschedule if the