diff options
Diffstat (limited to 'src/eu/siacs/conversations')
3 files changed, 77 insertions, 55 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<Message> mList = new ArrayList<Message>(); - mList.add(message); - notifications.put(conversationUuid, mList); + synchronized (notifications) { + String conversationUuid = message.getConversationUuid(); + if (notifications.containsKey(conversationUuid)) { + notifications.get(conversationUuid).add(message); + } else { + ArrayList<Message> mList = new ArrayList<Message>(); + 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); } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 5b0d9ea5..07897f8c 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -107,14 +107,15 @@ public class XmppConnectionService extends Service { private CopyOnWriteArrayList<Conversation> conversations = null; private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager( this); - private HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager(this); + private HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager( + this); private OnConversationUpdate mOnConversationUpdate = null; - private int convChangedListenerCount = 0; + private Integer convChangedListenerCount = 0; private OnAccountUpdate mOnAccountUpdate = null; - private int accountChangedListenerCount = 0; + private Integer accountChangedListenerCount = 0; private OnRosterUpdate mOnRosterUpdate = null; - private int rosterChangedListenerCount = 0; + private Integer rosterChangedListenerCount = 0; public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() { @Override @@ -976,71 +977,87 @@ public class XmppConnectionService extends Service { public void setOnConversationListChangedListener( OnConversationUpdate listener) { if (!isScreenOn()) { - Log.d(Config.LOGTAG,"ignoring setOnConversationListChangedListener"); + Log.d(Config.LOGTAG, + "ignoring setOnConversationListChangedListener"); return; } - this.mNotificationService.deactivateGracePeriod(); - if (checkListeners()) { - switchToForeground(); + synchronized (this.convChangedListenerCount) { + this.mNotificationService.deactivateGracePeriod(); + if (checkListeners()) { + switchToForeground(); + } + this.mOnConversationUpdate = listener; + this.mNotificationService.setIsInForeground(true); + this.convChangedListenerCount++; } - this.mOnConversationUpdate = listener; - this.mNotificationService.setIsInForeground(true); - this.convChangedListenerCount++; } public void removeOnConversationListChangedListener() { - this.convChangedListenerCount--; - if (this.convChangedListenerCount == 0) { - this.mOnConversationUpdate = null; - this.mNotificationService.setIsInForeground(false); - if (checkListeners()) { - switchToBackground(); + synchronized (this.convChangedListenerCount) { + this.convChangedListenerCount--; + if (this.convChangedListenerCount <= 0) { + this.convChangedListenerCount = 0; + this.mOnConversationUpdate = null; + this.mNotificationService.setIsInForeground(false); + if (checkListeners()) { + switchToBackground(); + } } } } public void setOnAccountListChangedListener(OnAccountUpdate listener) { if (!isScreenOn()) { - Log.d(Config.LOGTAG,"ignoring setOnAccountListChangedListener"); + Log.d(Config.LOGTAG, "ignoring setOnAccountListChangedListener"); return; } - this.mNotificationService.deactivateGracePeriod(); - if (checkListeners()) { - switchToForeground(); + synchronized (this.accountChangedListenerCount) { + this.mNotificationService.deactivateGracePeriod(); + if (checkListeners()) { + switchToForeground(); + } + this.mOnAccountUpdate = listener; + this.accountChangedListenerCount++; } - this.mOnAccountUpdate = listener; - this.accountChangedListenerCount++; } public void removeOnAccountListChangedListener() { - this.accountChangedListenerCount--; - if (this.accountChangedListenerCount == 0) { - this.mOnAccountUpdate = null; - if (checkListeners()) { - switchToBackground(); + synchronized (this.accountChangedListenerCount) { + this.accountChangedListenerCount--; + if (this.accountChangedListenerCount <= 0) { + this.mOnAccountUpdate = null; + this.accountChangedListenerCount = 0; + if (checkListeners()) { + switchToBackground(); + } } } } public void setOnRosterUpdateListener(OnRosterUpdate listener) { if (!isScreenOn()) { - Log.d(Config.LOGTAG,"ignoring setOnRosterUpdateListener"); + Log.d(Config.LOGTAG, "ignoring setOnRosterUpdateListener"); return; } - this.mNotificationService.deactivateGracePeriod(); - if (checkListeners()) { - switchToForeground(); + synchronized (this.rosterChangedListenerCount) { + this.mNotificationService.deactivateGracePeriod(); + if (checkListeners()) { + switchToForeground(); + } + this.mOnRosterUpdate = listener; + this.rosterChangedListenerCount++; } - this.mOnRosterUpdate = listener; - this.rosterChangedListenerCount++; } public void removeOnRosterUpdateListener() { - this.rosterChangedListenerCount--; - if (this.rosterChangedListenerCount == 0) { - this.mOnRosterUpdate = null; - if (checkListeners()) { - switchToBackground(); + synchronized (this.rosterChangedListenerCount) { + this.rosterChangedListenerCount--; + if (this.rosterChangedListenerCount <= 0) { + this.rosterChangedListenerCount = 0; + this.mOnRosterUpdate = null; + if (checkListeners()) { + switchToBackground(); + } } } } @@ -1075,9 +1092,10 @@ public class XmppConnectionService extends Service { } } } - + private boolean isScreenOn() { - PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); + PowerManager pm = (PowerManager) this + .getSystemService(Context.POWER_SERVICE); return pm.isScreenOn(); } @@ -1799,8 +1817,7 @@ public class XmppConnectionService extends Service { ArrayList<Contact> contacts = new ArrayList<Contact>(); for (Account account : getAccounts()) { if (!account.isOptionSet(Account.OPTION_DISABLED)) { - Contact contact = account.getRoster() - .getContactFromRoster(jid); + Contact contact = account.getRoster().getContactFromRoster(jid); if (contact != null) { contacts.add(contact); } diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 75f1dac8..4835636d 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -530,7 +530,6 @@ public class ConversationFragment extends Fragment { message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED); mDecryptJobRunning = false; mEncryptedMessages.remove(); - activity.updateConversationList(); activity.xmppConnectionService.updateConversationUi(); } }); |