diff options
4 files changed, 32 insertions, 46 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 98e330ad0..defc6244d 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -582,7 +582,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/standardPush/AndroidManifest.xml b/src/standardPush/AndroidManifest.xml index 08aafe900..cf94c879b 100644 --- a/src/standardPush/AndroidManifest.xml +++ b/src/standardPush/AndroidManifest.xml @@ -1,8 +1,9 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" package="de.pixart.messenger"> - <application> + <application tools:ignore="GoogleAppIndexingWarning"> <meta-data android:name="firebase_analytics_collection_deactivated" @@ -27,11 +28,5 @@ <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> - - <service android:name=".services.InstanceIdService"> - <intent-filter> - <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> - </intent-filter> - </service> </application> </manifest> diff --git a/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java b/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java deleted file mode 100644 index 9a3309be4..000000000 --- a/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.pixart.messenger.services; - -import android.content.Intent; -import android.support.v4.content.ContextCompat; -import android.util.Log; - -import com.google.firebase.iid.FirebaseInstanceIdService; - -import de.pixart.messenger.Config; -import de.pixart.messenger.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"); - } - } -}
\ No newline at end of file diff --git a/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java b/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java index f07167f8d..594225f3b 100644 --- a/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java +++ b/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java @@ -1,16 +1,16 @@ package de.pixart.messenger.services; -import android.content.Intent; -import android.support.v4.content.ContextCompat; -import android.util.Log; + import android.content.Intent; + import android.support.v4.content.ContextCompat; + import android.util.Log; -import com.google.firebase.messaging.FirebaseMessagingService; -import com.google.firebase.messaging.RemoteMessage; + import com.google.firebase.messaging.FirebaseMessagingService; + import com.google.firebase.messaging.RemoteMessage; -import java.util.Map; + import java.util.Map; -import de.pixart.messenger.Config; -import de.pixart.messenger.utils.Compatibility; + import de.pixart.messenger.Config; + import de.pixart.messenger.utils.Compatibility; public class PushMessageReceiver extends FirebaseMessagingService { @@ -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"); } } }
\ No newline at end of file |