Fix removal of notifications

This commit is contained in:
Andreas Böhler
2020-11-16 22:14:18 +01:00
committed by Gitea
parent 4fe057e56b
commit 4ad8eaab89

View File

@@ -288,7 +288,7 @@ public class NotificationListener extends NotificationListenerService {
} }
} }
if (shouldIgnoreNotification(sbn)) { if (shouldIgnoreNotification(sbn, false)) {
if (!"com.sec.android.app.clockpackage".equals(sbn.getPackageName())) { // workaround to allow phone alarm notification if (!"com.sec.android.app.clockpackage".equals(sbn.getPackageName())) { // workaround to allow phone alarm notification
LOG.info("Ignore notification: " + sbn.getPackageName()); // need to fix LOG.info("Ignore notification: " + sbn.getPackageName()); // need to fix
return; return;
@@ -317,7 +317,7 @@ public class NotificationListener extends NotificationListenerService {
} }
} }
NotificationSpec notificationSpec = new NotificationSpec(); NotificationSpec notificationSpec = new NotificationSpec(sbn.getId());
// determinate Source App Name ("Label") // determinate Source App Name ("Label")
String name = getAppName(source); String name = getAppName(source);
@@ -719,12 +719,12 @@ public class NotificationListener extends NotificationListenerService {
} }
// FIXME: DISABLED for now // FIXME: DISABLED for now
if (shouldIgnoreNotification(sbn)) return; if (shouldIgnoreNotification(sbn, true)) return;
Prefs prefs = GBApplication.getPrefs(); Prefs prefs = GBApplication.getPrefs();
if (prefs.getBoolean("autoremove_notifications", true)) { if (prefs.getBoolean("autoremove_notifications", true)) {
LOG.info("notification removed, will ask device to delete it"); LOG.info("notification removed, will ask device to delete it");
GBApplication.deviceService().onDeleteNotification((int) sbn.getPostTime()); GBApplication.deviceService().onDeleteNotification(sbn.getId());
} }
} }
@@ -802,7 +802,7 @@ public class NotificationListener extends NotificationListenerService {
return false; return false;
} }
private boolean shouldIgnoreNotification(StatusBarNotification sbn) { private boolean shouldIgnoreNotification(StatusBarNotification sbn, boolean remove) {
Notification notification = sbn.getNotification(); Notification notification = sbn.getNotification();
String source = sbn.getPackageName(); String source = sbn.getPackageName();
@@ -817,12 +817,16 @@ public class NotificationListener extends NotificationListenerService {
return true; return true;
} }
Prefs prefs = GBApplication.getPrefs(); // Check for screen on when posting the notification; for removal, the screen
if (!prefs.getBoolean("notifications_generic_whenscreenon", false)) { // has to be on (obviously)
PowerManager powermanager = (PowerManager) getSystemService(POWER_SERVICE); if(!remove) {
if (powermanager != null && powermanager.isScreenOn()) { Prefs prefs = GBApplication.getPrefs();
LOG.info("Not forwarding notification, screen seems to be on and settings do not allow this"); if (!prefs.getBoolean("notifications_generic_whenscreenon", false)) {
return true; PowerManager powermanager = (PowerManager) getSystemService(POWER_SERVICE);
if (powermanager != null && powermanager.isScreenOn()) {
LOG.info("Not forwarding notification, screen seems to be on and settings do not allow this");
return true;
}
} }
} }