Ignore notifications from suspended apps (#6082)

This commit is contained in:
José Rebelo
2026-05-10 16:28:06 +01:00
parent 7e1240da48
commit d2c66064ee
3 changed files with 28 additions and 11 deletions
+1
View File
@@ -84,6 +84,7 @@
* Huawei: Fix crash on sync for some devices
* Huawei: Fix watchface installation on some devices
* Huawei: Improve workout sync error handling
* Ignore notifications from suspended apps
* Improve battery notifications
* Include awake-sleep duration in sleep sessions
* Intent API: Add Intent to change global settings
@@ -65,7 +65,6 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalTime;
import java.util.ArrayList;
@@ -383,6 +382,21 @@ public class NotificationListener extends NotificationListenerService {
if (rankingMap.getRanking(sbn.getKey(), ranking)) {
if (!ranking.matchesInterruptionFilter()) dndSuppressed = 1;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// Digital Wellbeing app pause and similar restrictions can suppress notifications
// changing the interruption filter, but the app will be marked as suspended
if (ranking.isSuspended()) {
LOG.debug("Ignoring notification - app is suspended");
return;
}
// If importance is none, it should also not even show up
if (ranking.getImportance() == NotificationManager.IMPORTANCE_NONE) {
LOG.debug("Ignoring notification - importance is NONE");
return;
}
}
}
if (prefs.getBoolean("notification_filter", false) && dndSuppressed == 1) {
@@ -482,7 +496,7 @@ public class NotificationListener extends NotificationListenerService {
LOG.info(
"Processing notification {}, age: {}, source: {}, flags: {}",
notificationSpec.getId(),
(System.currentTimeMillis() - notification.when) ,
(System.currentTimeMillis() - notification.when),
source,
notification.flags
);
@@ -1112,6 +1126,7 @@ public class NotificationListener extends NotificationListenerService {
this.notificationPictureCacheDirectory = new File(cacheDir, "notification-pictures");
this.notificationPictureCacheDirectory.mkdir();
}
private void logNotification(StatusBarNotification sbn, boolean posted) {
LOG.debug(
"Notification {} {}: packageName={}, when={}, priority={}, category={}",
@@ -83,6 +83,7 @@
<change>Huawei: Fix crash on sync for some devices</change>
<change>Huawei: Fix watchface installation on some devices</change>
<change>Huawei: Improve workout sync error handling</change>
<change>Ignore notifications from suspended apps</change>
<change>Improve battery notifications</change>
<change>Include awake-sleep duration in sleep sessions</change>
<change>Intent API: Add Intent to change global settings</change>