summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Christopher Tate <ctate@google.com> 2021-04-28 10:12:09 -0700
committer Christopher Tate <ctate@google.com> 2021-05-04 13:16:10 -0700
commit2de948bbee902514ac30c9d8363067c206d9a7d0 (patch)
treed8c6532bab3c222894e1e2d0d9c9ed7ecf6aac31
parentfbd8deba683d469b8958f4dcef25c3b8dc5b5c92 (diff)
Don't defer FGS notification if it's already shown
Bug: 185523487 Test: atest CtsAppTestCases:android.app.cts.ServiceTest#testForegroundService_deferredExistingNotification Change-Id: I081a3cc8862caf4d53dbd46be1b8b1d4e626ebc0
-rw-r--r--services/core/java/com/android/server/am/ActiveServices.java12
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerInternal.java3
-rwxr-xr-xservices/core/java/com/android/server/notification/NotificationManagerService.java7
3 files changed, 22 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 5700bb367b04..b26123179411 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -155,6 +155,7 @@ import com.android.server.AppStateTracker;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.am.ActivityManagerService.ItemMatcher;
+import com.android.server.notification.NotificationManagerInternal;
import com.android.server.uri.NeededUriGrants;
import com.android.server.wm.ActivityServiceConnectionsHolder;
@@ -1977,6 +1978,17 @@ public final class ActiveServices {
showNow = isLegacyApp && mAm.mConstants.mFlagFgsNotificationDeferralApiGated;
}
if (!showNow) {
+ // did we already show it?
+ showNow = r.mFgsNotificationShown;
+ }
+ if (!showNow) {
+ // Is the notification already showing for any reason?
+ final NotificationManagerInternal nmi =
+ LocalServices.getService(NotificationManagerInternal.class);
+ showNow = nmi.isNotificationShown(r.appInfo.packageName, null,
+ r.foregroundId, UserHandle.getUserId(uid));
+ }
+ if (!showNow) {
// has the app forced deferral?
if (!r.foregroundNoti.isForegroundDisplayForceDeferred()) {
// is the notification such that it should show right away?
diff --git a/services/core/java/com/android/server/notification/NotificationManagerInternal.java b/services/core/java/com/android/server/notification/NotificationManagerInternal.java
index dc9839c6da0e..0528b95d1a6e 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerInternal.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerInternal.java
@@ -30,6 +30,9 @@ public interface NotificationManagerInternal {
void cancelNotification(String pkg, String basePkg, int callingUid, int callingPid,
String tag, int id, int userId);
+ /** is the given notification currently showing? */
+ boolean isNotificationShown(String pkg, String tag, int notificationId, int userId);
+
void removeForegroundServiceFlagFromNotification(String pkg, int notificationId, int userId);
void onConversationRemoved(String pkg, int uid, Set<String> shortcuts);
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 08a7d9e38d96..35ad01483b21 100755
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -6030,6 +6030,13 @@ public class NotificationManagerService extends SystemService {
}
@Override
+ public boolean isNotificationShown(String pkg, String tag, int notificationId, int userId) {
+ synchronized (mNotificationLock) {
+ return findNotificationLocked(pkg, tag, notificationId, userId) != null;
+ }
+ }
+
+ @Override
public void removeForegroundServiceFlagFromNotification(String pkg, int notificationId,
int userId) {
checkCallerIsSystem();