diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-11-12 14:41:43 +0100 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-11-15 15:34:34 +0100 |
commit | 3c6b3506e32979b80dc2a8163437ecbab16b8acb (patch) | |
tree | 3d240e476af1fd384e13a4da62d850a5cf82a509 /src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | |
parent | 4c504dea7ac7b0413df89ec630408b91f4abddb4 (diff) |
turn on foreground service in expert settings
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 831a54e12..97aba64fa 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -97,6 +97,7 @@ public class XmppConnectionService extends Service { public static String ACTION_CLEAR_NOTIFICATION = "clear_notification"; private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts"; + public static String ACTION_DISABLE_FOREGROUND = "disable_foreground"; private ContentObserver contactObserver = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { @@ -345,6 +346,9 @@ public class XmppConnectionService extends Service { return START_NOT_STICKY; } else if (intent.getAction().equals(ACTION_CLEAR_NOTIFICATION)) { mNotificationService.clear(); + } else if (intent.getAction().equals(ACTION_DISABLE_FOREGROUND)) { + getPreferences().edit().putBoolean("keep_foreground_service",false).commit(); + toggleForegroundService(); } } this.wakeLock.acquire(); @@ -459,18 +463,23 @@ public class XmppConnectionService extends Service { this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE); this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XmppConnectionService"); + toggleForegroundService(); } - @Override - public void onDestroy() { - super.onDestroy(); - this.logoutAndSave(); + public void toggleForegroundService() { + if (getPreferences().getBoolean("keep_foreground_service",false)) { + startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification()); + } else { + stopForeground(true); + } } @Override public void onTaskRemoved(Intent rootIntent) { super.onTaskRemoved(rootIntent); - this.logoutAndSave(); + if (!getPreferences().getBoolean("keep_foreground_service",false)) { + this.logoutAndSave(); + } } private void logoutAndSave() { |