Allow interrupting notifications to bypass lifetime extension

Notifications which have interruped the UI (usually a HUN) can safely
bypass FGS lifetime extension because the system has done the best it
can to show the user this notification.

This valve is important in particular for things like a dialer which
might want to interrupt a user but need to do so again on the same
channel, for instance when getting multiple phone calls quickly in
succession.

Bug: 155594347
Test: atest ForegroundServiceNotificationListenerTest
Change-Id: Id80fba3191cc133d1e73ca04015f9cbed62fc086
This commit is contained in:
Evan Laird
2020-05-27 23:46:32 -04:00
parent 7e24d133d0
commit 1d7db5b9ee
2 changed files with 18 additions and 0 deletions

View File

@@ -66,6 +66,12 @@ public class ForegroundServiceLifetimeExtender implements NotificationLifetimeEx
return false;
}
// Entry has triggered a HUN or some other interruption, therefore it has been seen and the
// interrupter might be retaining it anyway.
if (entry.hasInterrupted()) {
return false;
}
boolean hasInteracted = mInteractionTracker.hasUserInteractedWith(entry.getKey());
long aliveTime = mSystemClock.uptimeMillis() - entry.getCreationTime();
return aliveTime < MIN_FGS_TIME_MS && !hasInteracted;

View File

@@ -95,4 +95,16 @@ public class ForegroundServiceNotificationListenerTest extends SysuiTestCase {
mClock.advanceTime(MIN_FGS_TIME_MS + 1);
assertFalse(mExtender.shouldExtendLifetime(mEntry));
}
@Test
public void testShouldExtendLifetime_shouldNot_interruped() {
// GIVEN a notification that would trigger lifetime extension
mNotif.flags |= Notification.FLAG_FOREGROUND_SERVICE;
// GIVEN the notification has alerted
mEntry.setInterruption();
// THEN the notification does not need to have its lifetime extended by this extender
assertFalse(mExtender.shouldExtendLifetime(mEntry));
}
}