From 042779557870acb272c6b132cd2314e53c35317a Mon Sep 17 00:00:00 2001 From: mmanjuna Date: Fri, 22 Mar 2024 12:46:15 -0400 Subject: Response stats:counts are not updated sometimes This problem occurs only when the timestamp of broadcast and the notification event is exactly the same. Though ideally they need to occur one after the other, it is quite possible that they can occur immediately with the same timestamp. Hence, we see flaky behaviour. Fix is to process the events even if broadcast event's timestamp is equal to the notification event. Bug: 330844354 Test: atest tests/tests/app.usage/src/android/app/usage/cts/BroadcastResponse StatsTest.java Change-Id: I69398c1d15ed7a4ae39c31a2b56f19ef0b858614 --- .../java/com/android/server/usage/BroadcastResponseStatsTracker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/usage/java/com/android/server/usage/BroadcastResponseStatsTracker.java b/services/usage/java/com/android/server/usage/BroadcastResponseStatsTracker.java index d9cbea95e563..ed89190f8473 100644 --- a/services/usage/java/com/android/server/usage/BroadcastResponseStatsTracker.java +++ b/services/usage/java/com/android/server/usage/BroadcastResponseStatsTracker.java @@ -181,7 +181,7 @@ class BroadcastResponseStatsTracker { // We only need to look at the broadcast events that occurred before // this notification related event. while (dispatchTimestampsMs.size() > 0 - && dispatchTimestampsMs.peekFirst() < timestampMs) { + && dispatchTimestampsMs.peekFirst() <= timestampMs) { final long dispatchTimestampMs = dispatchTimestampsMs.peekFirst(); final long elapsedDurationMs = timestampMs - dispatchTimestampMs; // Only increment the counts if the broadcast was sent not too long ago, as -- cgit v1.2.3