aboutsummaryrefslogtreecommitdiffstats
path: root/src/standardPush/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-11-23 14:22:01 +0100
committerChristian Schneppe <christian@pix-art.de>2018-11-23 14:22:01 +0100
commit5af8fae06ff1e9a26e544a22c1ea40b4a5144353 (patch)
treed41117a87c2d69d6595a2c51b8795ca1e3bc0f7d /src/standardPush/java/de/pixart/messenger
parentfcea59be2be60164f82d23e45d5fe1d858fa9322 (diff)
use startForegroundService compat from push message receiver
Diffstat (limited to 'src/standardPush/java/de/pixart/messenger')
-rw-r--r--src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java11
-rw-r--r--src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java11
-rw-r--r--src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java15
3 files changed, 26 insertions, 11 deletions
diff --git a/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java b/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java
index d812105aa..465f974e6 100644
--- a/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java
+++ b/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java
@@ -13,12 +13,13 @@ public class InstanceIdService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
- Intent intent = new Intent(this, XmppConnectionService.class);
+ 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 (Exception e) {
- Log.e(Config.LOGTAG, "unable to refresh FCM token", e);
}
}
-}
+} \ No newline at end of file
diff --git a/src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java b/src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java
index 9368913bc..5706a487a 100644
--- a/src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java
+++ b/src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java
@@ -3,6 +3,7 @@ package de.pixart.messenger.services;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.support.v4.content.ContextCompat;
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
@@ -10,6 +11,7 @@ import com.google.firebase.iid.FirebaseInstanceId;
import java.io.IOException;
import de.pixart.messenger.Config;
+import de.pixart.messenger.utils.Compatibility;
public class MaintenanceReceiver extends BroadcastReceiver {
@Override
@@ -25,9 +27,14 @@ public class MaintenanceReceiver extends BroadcastReceiver {
new Thread(() -> {
try {
FirebaseInstanceId.getInstance().deleteInstanceId();
- Intent intent = new Intent(context, XmppConnectionService.class);
+ final Intent intent = new Intent(context, XmppConnectionService.class);
intent.setAction(XmppConnectionService.ACTION_FCM_TOKEN_REFRESH);
- context.startService(intent);
+ if (Compatibility.runsAndTargetsTwentySix(context)) {
+ intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true);
+ ContextCompat.startForegroundService(context, intent);
+ } else {
+ context.startService(intent);
+ }
} catch (IOException e) {
Log.d(Config.LOGTAG, "unable to renew instance token", e);
}
diff --git a/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java b/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java
index 816d11118..88b60e348 100644
--- a/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java
+++ b/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java
@@ -1,6 +1,7 @@
package de.pixart.messenger.services;
import android.content.Intent;
+import android.support.v4.content.ContextCompat;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
@@ -9,6 +10,7 @@ import com.google.firebase.messaging.RemoteMessage;
import java.util.Map;
import de.pixart.messenger.Config;
+import de.pixart.messenger.utils.Compatibility;
public class PushMessageReceiver extends FirebaseMessagingService {
@@ -18,10 +20,15 @@ public class PushMessageReceiver extends FirebaseMessagingService {
Log.d(Config.LOGTAG, "PushMessageReceiver ignored message because no accounts are enabled");
return;
}
- Map<String, String> data = message.getData();
- Intent intent = new Intent(this, XmppConnectionService.class);
+ final Map<String, String> data = message.getData();
+ final Intent intent = new Intent(this, XmppConnectionService.class);
intent.setAction(XmppConnectionService.ACTION_FCM_MESSAGE_RECEIVED);
intent.putExtra("account", data.get("account"));
- startService(intent);
+ if (Compatibility.runsAndTargetsTwentySix(this)) {
+ intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true);
+ ContextCompat.startForegroundService(this, intent);
+ } else {
+ startService(intent);
+ }
}
-}
+} \ No newline at end of file