From f063b1c063ec25698a2406233e742a1c7b0d9a93 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 15 Oct 2014 14:33:13 +0200 Subject: [PATCH] synchronization for notification --- .../services/NotificationService.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java index 41656707..e65085fb 100644 --- a/src/eu/siacs/conversations/services/NotificationService.java +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -43,34 +43,40 @@ public class NotificationService { .getSystemService(Context.NOTIFICATION_SERVICE); } - public synchronized void push(Message message) { - + public void push(Message message) { PowerManager pm = (PowerManager) mXmppConnectionService .getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); + if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) { return; } - String conversationUuid = message.getConversationUuid(); - if (notifications.containsKey(conversationUuid)) { - notifications.get(conversationUuid).add(message); - } else { - ArrayList mList = new ArrayList(); - mList.add(message); - notifications.put(conversationUuid, mList); + synchronized (notifications) { + String conversationUuid = message.getConversationUuid(); + if (notifications.containsKey(conversationUuid)) { + notifications.get(conversationUuid).add(message); + } else { + ArrayList mList = new ArrayList(); + mList.add(message); + notifications.put(conversationUuid, mList); + } } updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn) && !inGracePeriod()); } public void clear() { - notifications.clear(); + synchronized (notifications) { + notifications.clear(); + } updateNotification(false); } public void clear(Conversation conversation) { - notifications.remove(conversation.getUuid()); + synchronized (notifications) { + notifications.remove(conversation.getUuid()); + } updateNotification(false); }