aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-09-17 20:19:20 +0200
committerChristian Schneppe <christian@pix-art.de>2017-09-17 20:26:50 +0200
commit9522577e5ba97fa52277a5d7ba9163687743ba24 (patch)
treed5deda0fd87a8f3048c08ffa75839a5be6de3c15 /src/main/java/de/pixart/messenger/services/XmppConnectionService.java
parent58a4b628a6d21195ffc5a2b1e924dc1d3d90a225 (diff)
Foregroundservice can be deactivated in expert options (default = foregroundservice active)
Fixes #138
Diffstat (limited to 'src/main/java/de/pixart/messenger/services/XmppConnectionService.java')
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index fd431798c..71fb36014 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -160,7 +160,6 @@ public class XmppConnectionService extends Service {
public static final String ACTION_REPLY_TO_CONVERSATION = "reply_to_conversations";
public static final String ACTION_MARK_AS_READ = "mark_as_read";
public static final String ACTION_CLEAR_NOTIFICATION = "clear_notification";
- public static final String ACTION_DISABLE_FOREGROUND = "disable_foreground";
public static final String ACTION_TRY_AGAIN = "try_again";
public static final String ACTION_DISMISS_ERROR_NOTIFICATIONS = "dismiss_error";
public static final String ACTION_IDLE_PING = "idle_ping";
@@ -1121,6 +1120,11 @@ public class XmppConnectionService extends Service {
Log.d(Config.LOGTAG, "number of restarts exceeds threshold.");
}
+ if (this.accounts.size() == 0 && Arrays.asList("Sony","Sony Ericsson").contains(Build.MANUFACTURER)) {
+ getPreferences().edit().putBoolean(SettingsActivity.SHOW_FOREGROUND_SERVICE, true).commit();
+ Log.d(Config.LOGTAG, Build.MANUFACTURER + " is on blacklist. enabling foreground service");
+ }
+
restoreFromDatabase();
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver);
@@ -1203,7 +1207,7 @@ public class XmppConnectionService extends Service {
}
public void toggleForegroundService() {
- if (Config.USE_ALWAYS_FOREGROUND) {
+ if (showForegroundService()) {
startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification());
} else {
stopForeground(true);
@@ -1213,7 +1217,7 @@ public class XmppConnectionService extends Service {
@Override
public void onTaskRemoved(final Intent rootIntent) {
super.onTaskRemoved(rootIntent);
- if (!Config.USE_ALWAYS_FOREGROUND) {
+ if (!showForegroundService()) {
this.logoutAndSave(false);
} else {
Log.d(Config.LOGTAG,"ignoring onTaskRemoved because foreground service is activated");
@@ -2005,6 +2009,7 @@ public class XmppConnectionService extends Service {
this.accounts.add(account);
this.reconnectAccountInBackground(account);
updateAccountUi();
+ toggleForegroundService();
}
public void createAccountFromKey(final String alias, final OnAccountCreated callback) {
@@ -2078,6 +2083,7 @@ public class XmppConnectionService extends Service {
reconnectAccountInBackground(account);
updateAccountUi();
getNotificationService().updateErrorNotification();
+ toggleForegroundService();
return true;
} else {
return false;
@@ -4177,6 +4183,10 @@ public class XmppConnectionService extends Service {
return getPreferences().getBoolean(SettingsActivity.BLIND_TRUST_BEFORE_VERIFICATION, getResources().getBoolean(R.bool.btbv));
}
+ public boolean showForegroundService() {
+ return getPreferences().getBoolean(SettingsActivity.SHOW_FOREGROUND_SERVICE, getResources().getBoolean(R.bool.show_foreground_service));
+ }
+
public void pushMamPreferences(Account account, Element prefs) {
IqPacket set = new IqPacket(IqPacket.TYPE.SET);
set.addChild(prefs);