From 383b32c80d5d4a26fc1bc96ce790ceff3ce4d53b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 20 May 2018 12:01:07 +0200 Subject: [PATCH] make fcm receiver ignore messages when all accounts are disabled --- .../eu/siacs/conversations/services/EventReceiver.java | 2 +- .../siacs/conversations/services/PushMessageReceiver.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/services/EventReceiver.java b/src/main/java/eu/siacs/conversations/services/EventReceiver.java index b82338681..9b44bf2f7 100644 --- a/src/main/java/eu/siacs/conversations/services/EventReceiver.java +++ b/src/main/java/eu/siacs/conversations/services/EventReceiver.java @@ -34,7 +34,7 @@ public class EventReceiver extends BroadcastReceiver { } } - public boolean hasEnabledAccounts(Context context) { + public static boolean hasEnabledAccounts(Context context) { return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTING_ENABLED_ACCOUNTS,true); } diff --git a/src/playstore/java/eu/siacs/conversations/services/PushMessageReceiver.java b/src/playstore/java/eu/siacs/conversations/services/PushMessageReceiver.java index f6efa9b0d..7f36ceaa0 100644 --- a/src/playstore/java/eu/siacs/conversations/services/PushMessageReceiver.java +++ b/src/playstore/java/eu/siacs/conversations/services/PushMessageReceiver.java @@ -1,16 +1,23 @@ package eu.siacs.conversations.services; import android.content.Intent; +import android.util.Log; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; import java.util.Map; +import eu.siacs.conversations.Config; + public class PushMessageReceiver extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage message) { + if (!EventReceiver.hasEnabledAccounts(this)) { + Log.d(Config.LOGTAG,"PushMessageReceiver ignored message because no accounts are enabled"); + return; + } Map data = message.getData(); Intent intent = new Intent(this, XmppConnectionService.class); intent.setAction(XmppConnectionService.ACTION_FCM_MESSAGE_RECEIVED);