From 7d44291900e38e7bb3c849df95dbdd7d555f0d35 Mon Sep 17 00:00:00 2001 From: Evan Laird Date: Wed, 2 Oct 2019 18:33:49 -0400 Subject: [PATCH] Fix FGS lifetime extender overzealousness ForegroundServiceLifetimeExtender was always posting MIN_FGS_TIME_MS in the future to release a notification if it was canceled at any time before the minimum. Meaning that if a foreground service was started and then stopped 4.9 seconds later, it woudn't be released until 9.9 seconds due to always posting 5000ms. This change takes into consideration the time that a notification has already been showing. Fixes: 141688100 Test: atest ForegroundServiceNotificationListenerTest Change-Id: Ie0403ddb37bb85a602a5ac6ffedcaf4bab2efcbc --- .../android/systemui/ForegroundServiceLifetimeExtender.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/ForegroundServiceLifetimeExtender.java b/packages/SystemUI/src/com/android/systemui/ForegroundServiceLifetimeExtender.java index 0e079e36a175b..5c561e5bf6f2c 100644 --- a/packages/SystemUI/src/com/android/systemui/ForegroundServiceLifetimeExtender.java +++ b/packages/SystemUI/src/com/android/systemui/ForegroundServiceLifetimeExtender.java @@ -83,7 +83,9 @@ public class ForegroundServiceLifetimeExtender implements NotificationLifetimeEx } } }; - mHandler.postDelayed(r, MIN_FGS_TIME_MS); + long delayAmt = MIN_FGS_TIME_MS + - (System.currentTimeMillis() - entry.notification.getPostTime()); + mHandler.postDelayed(r, delayAmt); } }