From 4c88fce3b8fae0419e01f5eb9b4b733ec5ee1cac Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 11 Nov 2018 09:54:52 +0100 Subject: [PATCH] =?UTF-8?q?do=20not=20update=20foreground=20notification?= =?UTF-8?q?=20on=20error=20if=20it=20wasn=E2=80=99t=20enabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/NotificationService.java | 21 ++++++++----------- .../services/XmppConnectionService.java | 4 ++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 9269fd7fa..e9491d45d 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -31,8 +31,6 @@ import android.util.DisplayMetrics; import android.util.Log; import android.util.Pair; -import org.conscrypt.Conscrypt; - import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -73,7 +71,7 @@ public class NotificationService { private static final String CONVERSATIONS_GROUP = "eu.siacs.conversations"; private static final int NOTIFICATION_ID_MULTIPLIER = 1024 * 1024; private static final int NOTIFICATION_ID = 2 * NOTIFICATION_ID_MULTIPLIER; - public static final int FOREGROUND_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 4; + static final int FOREGROUND_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 4; private static final int ERROR_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 6; private final XmppConnectionService mXmppConnectionService; private final LinkedHashMap> notifications = new LinkedHashMap<>(); @@ -226,7 +224,7 @@ public class NotificationService { } } - public void pushFromDirectReply(final Message message) { + void pushFromDirectReply(final Message message) { synchronized (notifications) { pushToStack(message); updateNotification(false); @@ -252,8 +250,7 @@ public class NotificationService { private List getBacklogConversations(Account account) { final List conversations = new ArrayList<>(); - for (Iterator> it = mBacklogMessageCounter.entrySet().iterator(); it.hasNext(); ) { - Map.Entry entry = it.next(); + for (Map.Entry entry : mBacklogMessageCounter.entrySet()) { if (entry.getKey().getAccount() == account) { conversations.add(entry.getKey().getUuid()); } @@ -274,7 +271,7 @@ public class NotificationService { return count; } - public void finishBacklog(boolean notify) { + void finishBacklog(boolean notify) { finishBacklog(notify, null); } @@ -369,7 +366,7 @@ public class NotificationService { updateNotification(notify, null, false); } - public void updateNotification(final boolean notify, final List conversations) { + private void updateNotification(final boolean notify, final List conversations) { updateNotification(notify, conversations, false); } @@ -885,7 +882,7 @@ public class NotificationService { return PendingIntent.getActivity(mXmppConnectionService, 0, new Intent(mXmppConnectionService, ConversationsActivity.class), 0); } - public void updateErrorNotification() { + void updateErrorNotification() { if (Config.SUPPRESS_ERROR_NOTIFICATION) { cancel(ERROR_NOTIFICATION_ID); return; @@ -897,7 +894,7 @@ public class NotificationService { errors.add(account); } } - if (Compatibility.keepForegroundService(mXmppConnectionService)) { + if (mXmppConnectionService.foregroundNotificationNeedsUpdatingWhenErrorStateChanges()) { notify(FOREGROUND_NOTIFICATION_ID, createForegroundNotification()); } final Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService); @@ -940,7 +937,7 @@ public class NotificationService { notify(ERROR_NOTIFICATION_ID, mBuilder.build()); } - public void updateFileAddingNotification(int current, Message message) { + void updateFileAddingNotification(int current, Message message) { Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService); mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.transcoding_video)); mBuilder.setProgress(100, current, false); @@ -954,7 +951,7 @@ public class NotificationService { notify(FOREGROUND_NOTIFICATION_ID, notification); } - public void dismissForcedForegroundNotification() { + void dismissForcedForegroundNotification() { cancel(FOREGROUND_NOTIFICATION_ID); } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 207ea2405..a3f244930 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1105,6 +1105,10 @@ public class XmppConnectionService extends Service { Log.d(Config.LOGTAG,"ForegroundService: "+(status?"on":"off")); } + public boolean foregroundNotificationNeedsUpdatingWhenErrorStateChanges() { + return !mForceForegroundService.get() && Compatibility.keepForegroundService(this) && hasEnabledAccounts(); + } + @Override public void onTaskRemoved(final Intent rootIntent) { super.onTaskRemoved(rootIntent);