diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 5700bb367b041..b261231794110 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; @@ -1976,6 +1977,17 @@ public final class ActiveServices { // DeviceConfig element has been set 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()) { diff --git a/services/core/java/com/android/server/notification/NotificationManagerInternal.java b/services/core/java/com/android/server/notification/NotificationManagerInternal.java index dc9839c6da0ef..0528b95d1a6e6 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 shortcuts); diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 0840e75823b50..6083bc5612192 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -6047,6 +6047,13 @@ public class NotificationManagerService extends SystemService { cancelNotificationInternal(pkg, opPkg, callingUid, callingPid, tag, id, userId); } + @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) {