OSDN Git Service

Force FGS notifications to show for a minimum time
authorEvan Laird <evanlaird@google.com>
Wed, 6 Nov 2019 19:04:59 +0000 (14:04 -0500)
committerKyriakos Ispoglou <ispo@google.com>
Fri, 8 Nov 2019 23:55:50 +0000 (15:55 -0800)
commit15273ad9f1c5dc34e788350b559b1a3f0f46facf
tree9401ccb5a749de14b73804a910e7b18ca370da75
parentef7e2882a5c3b48a9610070a8df81dc429189bda
Force FGS notifications to show for a minimum time

It's possible for a service to do a start/stop foreground and cause a
couple of things to happen:

NotificationManagerService will enqueue a EnqueueNotificationRunnable,
post a PostNotificationRunnable (for the startForeground), and then also
enqueue a CancelNotificationRunnable. There is some racy behavior here
in that the cancel runnable can get triggered in between enqueue and
post runnables. If the cancel happens first, then
NotificationListenerServices will never get the message.

This behavior is technically allowed, however for foreground services we
want to ensure that there is a minmum amount of time that notification
listeners are aware of the foreground service so that (for instance) the
FGS notification can be shown.

This CL does two things to mitigate this problem:

1. Introduce checking in the CancelNotificationRunnable such that it
will not cancel until after PostNotificationRunnable has finished
executing.

2. Introduce a NotificationLifetimeExtender method that will allow a
lifetime extender to manage the lifetime of a notification that has been
enqueued but not inflated yet.

Bug: 119041698
Test: atest NotificationManagerServiceTest
Test: atest ForegroundServiceLifetimeExtenderTest
Change-Id: I0680034ed9315aa2c05282524d48faaed066ebd0
Merged-In: I0680034ed9315aa2c05282524d48faaed066ebd0
(cherry picked from commit 3692a6d231cef34f0a47a9b2802590d59eaf51e5)
packages/SystemUI/src/com/android/systemui/statusbar/ForegroundServiceLifetimeExtender.java [new file with mode: 0644]
packages/SystemUI/src/com/android/systemui/statusbar/NotificationLifetimeExtender.java [new file with mode: 0644]
packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
packages/SystemUI/tests/src/com/android/systemui/statusbar/ForegroundServiceLifetimeExtenderTest.java [new file with mode: 0644]
packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
services/core/java/com/android/server/notification/NotificationManagerService.java
services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java