From 25856992d199a76a661c246e9621a21c5cf81775 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 9 Jan 2019 17:37:52 +0100 Subject: [PATCH] remove deprecated instanceIdService --- .../services/XmppConnectionService.java | 2 +- src/playstore/AndroidManifest.xml | 10 ++----- .../services/InstanceIdService.java | 29 ------------------- .../services/PushMessageReceiver.java | 22 +++++++++++++- 4 files changed, 24 insertions(+), 39 deletions(-) delete mode 100644 src/playstore/java/eu/siacs/conversations/services/InstanceIdService.java diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index f7e9cf4a7..2708ea386 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -562,7 +562,7 @@ public class XmppConnectionService extends Service { final String action = intent == null ? null : intent.getAction(); final boolean needsForegroundService = intent != null && intent.getBooleanExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, false); if (needsForegroundService) { - Log.d(Config.LOGTAG,"toggle forced foreground service after receiving event"); + Log.d(Config.LOGTAG,"toggle forced foreground service after receiving event (action="+action+")"); toggleForegroundService(true); } String pushedAccountHash = null; diff --git a/src/playstore/AndroidManifest.xml b/src/playstore/AndroidManifest.xml index 654526433..6e65b581c 100644 --- a/src/playstore/AndroidManifest.xml +++ b/src/playstore/AndroidManifest.xml @@ -1,9 +1,9 @@ - - + @@ -23,11 +23,5 @@ - - - - - - diff --git a/src/playstore/java/eu/siacs/conversations/services/InstanceIdService.java b/src/playstore/java/eu/siacs/conversations/services/InstanceIdService.java deleted file mode 100644 index e33cd4d42..000000000 --- a/src/playstore/java/eu/siacs/conversations/services/InstanceIdService.java +++ /dev/null @@ -1,29 +0,0 @@ -package eu.siacs.conversations.services; - -import android.content.Intent; -import android.support.v4.content.ContextCompat; -import android.util.Log; - -import com.google.firebase.iid.FirebaseInstanceIdService; - -import eu.siacs.conversations.Config; -import eu.siacs.conversations.utils.Compatibility; - -public class InstanceIdService extends FirebaseInstanceIdService { - - @Override - public void onTokenRefresh() { - final Intent intent = new Intent(this, XmppConnectionService.class); - intent.setAction(XmppConnectionService.ACTION_FCM_TOKEN_REFRESH); - try { - if (Compatibility.runsAndTargetsTwentySix(this)) { - intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true); - ContextCompat.startForegroundService(this, intent); - } else { - startService(intent); - } - } catch (IllegalStateException e) { - Log.e(Config.LOGTAG,"InstanceIdService is not allowed to start service"); - } - } -} diff --git a/src/playstore/java/eu/siacs/conversations/services/PushMessageReceiver.java b/src/playstore/java/eu/siacs/conversations/services/PushMessageReceiver.java index 626e1fbe1..872afb849 100644 --- a/src/playstore/java/eu/siacs/conversations/services/PushMessageReceiver.java +++ b/src/playstore/java/eu/siacs/conversations/services/PushMessageReceiver.java @@ -32,7 +32,27 @@ public class PushMessageReceiver extends FirebaseMessagingService { startService(intent); } } catch (IllegalStateException e) { - Log.e(Config.LOGTAG,"PushMessageReceiver is not allowed to start service"); + Log.e(Config.LOGTAG,"PushMessageReceiver is not allowed to start service after receiving message"); + } + } + + @Override + public void onNewToken(String token) { + if (!EventReceiver.hasEnabledAccounts(this)) { + Log.d(Config.LOGTAG,"PushMessageReceiver ignored new token because no accounts are enabled"); + return; + } + final Intent intent = new Intent(this, XmppConnectionService.class); + intent.setAction(XmppConnectionService.ACTION_FCM_TOKEN_REFRESH); + try { + if (Compatibility.runsAndTargetsTwentySix(this)) { + intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true); + ContextCompat.startForegroundService(this, intent); + } else { + startService(intent); + } + } catch (IllegalStateException e) { + Log.e(Config.LOGTAG,"PushMessageReceiver is not allowed to start service after receiving new token"); } }