aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/services/EventReceiver.java4
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java11
2 files changed, 13 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/services/EventReceiver.java b/src/main/java/de/pixart/messenger/services/EventReceiver.java
index a77db569e..03bf68ed9 100644
--- a/src/main/java/de/pixart/messenger/services/EventReceiver.java
+++ b/src/main/java/de/pixart/messenger/services/EventReceiver.java
@@ -13,6 +13,7 @@ import de.pixart.messenger.utils.Compatibility;
public class EventReceiver extends BroadcastReceiver {
public static final String SETTING_ENABLED_ACCOUNTS = "enabled_accounts";
+ public static final String EXTRA_NEEDS_FOREGROUND_SERVICE = "needs_foreground_service";
@Override
public void onReceive(final Context context, final Intent originalIntent) {
@@ -26,6 +27,7 @@ public class EventReceiver extends BroadcastReceiver {
if (action.equals("ui") || hasEnabledAccounts(context)) {
try {
if (Compatibility.runsAndTargetsTwentySix(context)) {
+ intentForService.putExtra(EXTRA_NEEDS_FOREGROUND_SERVICE, true);
ContextCompat.startForegroundService(context, intentForService);
} else {
context.startService(intentForService);
@@ -42,4 +44,4 @@ public class EventReceiver extends BroadcastReceiver {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTING_ENABLED_ACCOUNTS, true);
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index c0c3c7dec..9d0071af2 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -581,6 +581,11 @@ public class XmppConnectionService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
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");
+ toggleForegroundService(true);
+ }
String pushedAccountHash = null;
boolean interactive = false;
if (action != null) {
@@ -1243,8 +1248,12 @@ public class XmppConnectionService extends Service {
}
public void toggleForegroundService() {
+ toggleForegroundService(false);
+ }
+
+ private void toggleForegroundService(boolean force) {
final boolean status;
- if (mForceForegroundService.get() || (Compatibility.keepForegroundService(this)/* && hasEnabledAccounts()*/)) {
+ if (force || mForceForegroundService.get() || (Compatibility.keepForegroundService(this)/* && hasEnabledAccounts()*/)) {
startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification());
status = true;
} else {