diff options
author | Dan Sandler <dsandler@android.com> | 2017-10-26 23:27:57 -0400 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-10-27 14:47:19 +0000 |
commit | ee62f699468260b4e993de899e9cef9d853018dd (patch) | |
tree | b68defcb321c455098c9f5027f46a6ec3ce9570b | |
parent | a36fe421702f1bf1abc7dfa5a9b9a897d47f15ef (diff) | |
download | base-ee62f699468260b4e993de899e9cef9d853018dd.tar.gz |
Give fg services a shelf life before they go bad.
When a fg service starts (as indicated by its presence in a
NOTE_FOREGROUND_SERVICES notification), we note the service
start time (as encoded in Notification.when in ActivityMgr).
SysUI will suppress the dungeon (foreground service
disclosure) notification until 5 seconds have elapsed since
the earliest service start time. After that, if the service
is still running, the disclosure will be shown.
Bug: 67819284
Test: runtest -x frameworks/base/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java
Change-Id: I5b6df95eb673e2f551aaa3ecc5a7df617f815a90
(cherry picked from commit 9830b5a8e41c3b477064e3b378734fc129e8342f)
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/ForegroundServiceControllerImpl.java | 16 | ||||
-rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java | 1 |
2 files changed, 13 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/ForegroundServiceControllerImpl.java b/packages/SystemUI/src/com/android/systemui/ForegroundServiceControllerImpl.java index c930d567254a..3714c4ea7e2c 100644 --- a/packages/SystemUI/src/com/android/systemui/ForegroundServiceControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/ForegroundServiceControllerImpl.java @@ -34,6 +34,10 @@ import java.util.Arrays; */ public class ForegroundServiceControllerImpl implements ForegroundServiceController { + + // shelf life of foreground services before they go bad + public static final long FG_SERVICE_GRACE_MILLIS = 5000; + private static final String TAG = "FgServiceController"; private static final boolean DBG = false; @@ -72,7 +76,7 @@ public class ForegroundServiceControllerImpl if (isDungeonNotification(sbn)) { // if you remove the dungeon entirely, we take that to mean there are // no running services - userServices.setRunningServices(null); + userServices.setRunningServices(null, 0); return true; } else { // this is safe to call on any notification, not just FLAG_FOREGROUND_SERVICE @@ -94,7 +98,7 @@ public class ForegroundServiceControllerImpl final Bundle extras = sbn.getNotification().extras; if (extras != null) { final String[] svcs = extras.getStringArray(Notification.EXTRA_FOREGROUND_APPS); - userServices.setRunningServices(svcs); // null ok + userServices.setRunningServices(svcs, sbn.getNotification().when); } } else { userServices.removeNotification(sbn.getPackageName(), sbn.getKey()); @@ -118,9 +122,11 @@ public class ForegroundServiceControllerImpl */ private static class UserServices { private String[] mRunning = null; + private long mServiceStartTime = 0; private ArrayMap<String, ArraySet<String>> mNotifications = new ArrayMap<>(1); - public void setRunningServices(String[] pkgs) { + public void setRunningServices(String[] pkgs, long serviceStartTime) { mRunning = pkgs != null ? Arrays.copyOf(pkgs, pkgs.length) : null; + mServiceStartTime = serviceStartTime; } public void addNotification(String pkg, String key) { if (mNotifications.get(pkg) == null) { @@ -142,7 +148,9 @@ public class ForegroundServiceControllerImpl return found; } public boolean isDungeonNeeded() { - if (mRunning != null) { + if (mRunning != null + && System.currentTimeMillis() - mServiceStartTime >= FG_SERVICE_GRACE_MILLIS) { + for (String pkg : mRunning) { final ArraySet<String> set = mNotifications.get(pkg); if (set == null || set.size() == 0) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java index 1f5255a0e869..943020c7b28e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java @@ -287,6 +287,7 @@ public class ForegroundServiceControllerTest extends SysuiTestCase { final Bundle extras = new Bundle(); if (pkgs != null) extras.putStringArray(Notification.EXTRA_FOREGROUND_APPS, pkgs); n.extras = extras; + n.when = System.currentTimeMillis() - 10000; // ten seconds ago final StatusBarNotification sbn = makeMockSBN(userid, "android", SystemMessageProto.SystemMessage.NOTE_FOREGROUND_SERVICES, null, n); |