From ebf783e1591550f9978a4c2e7e0959132e5d4848 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 18 Sep 2019 21:36:10 +0200 Subject: [PATCH] Fixed notification race condition --- app/src/main/java/eu/faircode/email/Core.java | 9 ++++++--- .../main/java/eu/faircode/email/ServiceSynchronize.java | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 63502e12d7..b62f463874 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -2083,8 +2083,11 @@ class Core { if (message.notifying != 0) { long id = message.id * message.notifying; - if (!groupNotifying.get(group).contains(id)) + if (!groupNotifying.get(group).contains(id) && + !groupNotifying.get(group).contains(-id)) { + Log.i("Notify database=" + id); groupNotifying.get(group).add(id); + } } if (!(message.ui_seen || message.ui_ignored || message.ui_hide != 0)) { @@ -2143,7 +2146,7 @@ class Core { for (Long id : remove) { String tag = "unseen." + group + "." + Math.abs(id); - Log.i("Notify cancel tag=" + tag); + Log.i("Notify cancel tag=" + tag + " id=" + id); nm.cancel(tag, 1); groupNotifying.get(group).remove(id); @@ -2154,7 +2157,7 @@ class Core { long id = notification.extras.getLong("id", 0); if ((id == 0 && add.size() + remove.size() > 0) || add.contains(id)) { String tag = "unseen." + group + "." + Math.abs(id); - Log.i("Notifying tag=" + tag + + Log.i("Notifying tag=" + tag + " id=" + id + (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : " channel=" + notification.getChannelId())); nm.notify(tag, 1, notification); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index dcf86384d5..bba31104f9 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -169,13 +169,13 @@ public class ServiceSynchronize extends ServiceBase { if (tag != null && tag.startsWith("unseen.")) { String[] p = tag.split(("\\.")); long group = Long.parseLong(p[1]); - long id = Long.parseLong(p[2]); + long id = sbn.getNotification().extras.getLong("id", 0); if (!groupNotifying.containsKey(group)) groupNotifying.put(group, new ArrayList<>()); if (id > 0) { - Log.i("Notify restore " + tag); + Log.i("Notify restore " + tag + " id=" + id); groupNotifying.get(group).add(id); } }