mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Improve notification logging
- Reduce duplicated and redundant messages - Log notification priority - Add log entry for notification ignored by dnd
This commit is contained in:
parent
eb7366c7e3
commit
0c52f3d3da
@ -56,6 +56,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -247,7 +248,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
// determinate Source App Name ("Label")
|
||||
PackageManager pm = getPackageManager();
|
||||
try {
|
||||
return (String)pm.getApplicationLabel(pm.getApplicationInfo(pkg, 0));
|
||||
return (String) pm.getApplicationLabel(pm.getApplicationInfo(pkg, 0));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -262,7 +263,6 @@ public class NotificationListener extends NotificationListenerService {
|
||||
@Override
|
||||
public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) {
|
||||
logNotification(sbn, true);
|
||||
LOG.debug("notificationAppListIsBlackList: " + GBApplication.getPrefs().getString("notification_list_is_blacklist","true"));
|
||||
|
||||
notificationStack.remove(sbn.getPackageName());
|
||||
notificationStack.add(sbn.getPackageName());
|
||||
@ -275,10 +275,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
// If media notifications ignore app list, check them before
|
||||
if (mediaIgnoresAppList && handleMediaSessionNotification(sbn)) return;
|
||||
|
||||
if (shouldIgnoreSource(sbn)) {
|
||||
LOG.debug("Ignoring notification source");
|
||||
return;
|
||||
}
|
||||
if (shouldIgnoreSource(sbn)) return;
|
||||
|
||||
// If media notifications do NOT ignore app list, check them after
|
||||
if (!mediaIgnoresAppList && handleMediaSessionNotification(sbn)) return;
|
||||
@ -293,8 +290,10 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("notification_filter", false) && dndSuppressed == 1) {
|
||||
LOG.debug("Ignoring notification because of do not disturb");
|
||||
return;
|
||||
}
|
||||
|
||||
if (NotificationCompat.CATEGORY_CALL.equals(sbn.getNotification().category)
|
||||
&& prefs.getBoolean("notification_support_voip_calls", false)
|
||||
&& sbn.isOngoing()) {
|
||||
@ -303,8 +302,8 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
|
||||
if (shouldIgnoreNotification(sbn, false)) {
|
||||
if (!"com.sec.android.app.clockpackage".equals(sbn.getPackageName())) { // workaround to allow phone alarm notification
|
||||
LOG.info("Ignore notification: " + sbn.getPackageName()); // need to fix
|
||||
if (!"com.sec.android.app.clockpackage".equals(sbn.getPackageName())) { // workaround to allow phone alarm notification
|
||||
LOG.info("Ignoring notification: {}", sbn.getPackageName()); // need to fix
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -316,8 +315,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
if (notificationOldRepeatPreventionValue != null
|
||||
&& notification.when <= notificationOldRepeatPreventionValue
|
||||
&& !shouldIgnoreRepeatPrevention(sbn)
|
||||
)
|
||||
{
|
||||
) {
|
||||
LOG.info("NOT processing notification, already sent newer notifications from this source.");
|
||||
return;
|
||||
}
|
||||
@ -328,8 +326,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
if (notificationBurstPreventionValue != null) {
|
||||
long diff = curTime - notificationBurstPreventionValue;
|
||||
if (diff < TimeUnit.SECONDS.toNanos(prefs.getInt("notifications_timeout", 0))) {
|
||||
LOG.info("Ignoring frequent notification, last one was "
|
||||
+ TimeUnit.NANOSECONDS.toMillis(diff) + "ms ago");
|
||||
LOG.info("Ignoring frequent notification, last one was {} ms ago", TimeUnit.NANOSECONDS.toMillis(diff));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -365,7 +362,13 @@ public class NotificationListener extends NotificationListenerService {
|
||||
// Get color
|
||||
notificationSpec.pebbleColor = getPebbleColorForNotification(notificationSpec);
|
||||
|
||||
LOG.info("Processing notification " + notificationSpec.getId() + " age: " + (System.currentTimeMillis() - notification.when) + " from source " + source + " with flags: " + notification.flags);
|
||||
LOG.info(
|
||||
"Processing notification {}, age: {}, source: {}, flags: {}",
|
||||
notificationSpec.getId(),
|
||||
(System.currentTimeMillis() - notification.when) ,
|
||||
source,
|
||||
notification.flags
|
||||
);
|
||||
|
||||
boolean preferBigText = prefs.getBoolean("notification_prefer_long_text", true);
|
||||
|
||||
@ -415,8 +418,8 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
|
||||
notificationSpec.attachedActions.add(wearableAction);
|
||||
mActionLookup.add((notificationSpec.getId()<<4) + notificationSpec.attachedActions.size(), act);
|
||||
LOG.info("found wearable action: " + notificationSpec.attachedActions.size() + " - "+ act.getTitle() + " " + sbn.getTag());
|
||||
mActionLookup.add((notificationSpec.getId() << 4) + notificationSpec.attachedActions.size(), act);
|
||||
LOG.info("Found wearable action: {} - {} {}", notificationSpec.attachedActions.size(), act.getTitle(), sbn.getTag());
|
||||
}
|
||||
}
|
||||
|
||||
@ -436,9 +439,9 @@ public class NotificationListener extends NotificationListenerService {
|
||||
mPackageLookup.add(notificationSpec.getId(), sbn.getPackageName()); // for MUTE
|
||||
|
||||
notificationBurstPrevention.put(source, curTime);
|
||||
if(0 != notification.when) {
|
||||
if (0 != notification.when) {
|
||||
notificationOldRepeatPrevention.put(source, notification.when);
|
||||
}else {
|
||||
} else {
|
||||
LOG.info("This app might show old/duplicate notifications. notification.when is 0 for " + source);
|
||||
}
|
||||
notificationsActive.add(notificationSpec.getId());
|
||||
@ -500,7 +503,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
Notification noti = sbn.getNotification();
|
||||
dumpExtras(noti.extras);
|
||||
boolean callStarted = false;
|
||||
if(noti.actions != null && noti.actions.length > 0) {
|
||||
if (noti.actions != null && noti.actions.length > 0) {
|
||||
for (Notification.Action action : noti.actions) {
|
||||
LOG.info("Found call action: " + action.title);
|
||||
}
|
||||
@ -524,9 +527,9 @@ public class NotificationListener extends NotificationListenerService {
|
||||
|
||||
// figure out sender
|
||||
String number;
|
||||
if(noti.extras.containsKey(Notification.EXTRA_PEOPLE)) {
|
||||
if (noti.extras.containsKey(Notification.EXTRA_PEOPLE)) {
|
||||
number = noti.extras.getString(Notification.EXTRA_PEOPLE);
|
||||
} else if(noti.extras.containsKey(Notification.EXTRA_TITLE)) {
|
||||
} else if (noti.extras.containsKey(Notification.EXTRA_TITLE)) {
|
||||
number = noti.extras.getString(Notification.EXTRA_TITLE);
|
||||
} else {
|
||||
String appName = getAppName(app);
|
||||
@ -740,7 +743,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
// If media notifications do NOT ignore app list, check them after
|
||||
if (!mediaIgnoresAppList && handleMediaSessionNotification(sbn)) return;
|
||||
|
||||
if(Notification.CATEGORY_CALL.equals(sbn.getNotification().category)
|
||||
if (Notification.CATEGORY_CALL.equals(sbn.getNotification().category)
|
||||
&& activeCallPostTime == sbn.getPostTime()) {
|
||||
activeCallPostTime = 0;
|
||||
CallSpec callSpec = new CallSpec();
|
||||
@ -755,7 +758,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
ArrayList<Integer> activeNotificationsIds = new ArrayList<Integer>();
|
||||
for (StatusBarNotification notification : getActiveNotifications()) {
|
||||
Object o = mNotificationHandleLookup.lookupByValue(notification.getPostTime());
|
||||
if(o != null) {
|
||||
if (o != null) {
|
||||
int id = (int) o;
|
||||
activeNotificationsIds.add(id);
|
||||
}
|
||||
@ -774,8 +777,8 @@ public class NotificationListener extends NotificationListenerService {
|
||||
|
||||
// Send notification remove request to device
|
||||
List<GBDevice> devices = GBApplication.app().getDeviceManager().getDevices();
|
||||
for(GBDevice device : devices){
|
||||
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()));
|
||||
for (GBDevice device : devices) {
|
||||
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()));
|
||||
if (devicePrefs.getBoolean("autoremove_notifications", true)) {
|
||||
for (int id : notificationsToRemove) {
|
||||
LOG.info("Notification " + id + " removed, will ask device to delete it");
|
||||
@ -786,16 +789,14 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
|
||||
private void logNotification(StatusBarNotification sbn, boolean posted) {
|
||||
String infoMsg = String.format(
|
||||
"Notification %d %s: %s",
|
||||
LOG.debug(
|
||||
"Notification {} {}: packageName={}, priority={}, category={}",
|
||||
sbn.getId(),
|
||||
posted ? "posted" : "removed",
|
||||
sbn.getPackageName()
|
||||
sbn.getPackageName(),
|
||||
sbn.getNotification().priority,
|
||||
sbn.getNotification().category
|
||||
);
|
||||
|
||||
infoMsg += ": " + sbn.getNotification().category;
|
||||
|
||||
LOG.debug(infoMsg);
|
||||
}
|
||||
|
||||
private void dumpExtras(Bundle bundle) {
|
||||
@ -808,7 +809,6 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean isServiceNotRunningAndShouldIgnoreNotifications() {
|
||||
/*
|
||||
* return early if DeviceCommunicationService is not running,
|
||||
@ -849,6 +849,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
source.equals("com.android.messaging") ||
|
||||
source.equals("org.smssecure.smssecure")) {
|
||||
if (!"never".equals(prefs.getString("notification_mode_sms", "when_screen_off"))) {
|
||||
LOG.info("Ignoring notification, it's an sms notification");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -911,7 +912,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
type != NotificationType.WECHAT &&
|
||||
type != NotificationType.OUTLOOK &&
|
||||
type != NotificationType.SKYPE) { //see https://github.com/Freeyourgadget/Gadgetbridge/issues/1109
|
||||
LOG.info("local only");
|
||||
LOG.info("Ignoring notification, local only");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -919,7 +920,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
|
||||
// Check for screen on when posting the notification; for removal, the screen
|
||||
// has to be on (obviously)
|
||||
if(!remove) {
|
||||
if (!remove) {
|
||||
if (!prefs.getBoolean("notifications_generic_whenscreenon", false)) {
|
||||
PowerManager powermanager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
if (powermanager != null && powermanager.isScreenOn()) {
|
||||
@ -936,7 +937,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldIgnoreOngoing(sbn)){
|
||||
if (shouldIgnoreOngoing(sbn)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user