diff options
Diffstat (limited to 'src/main/java/de')
4 files changed, 17 insertions, 26 deletions
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java index 87e494af2..2dc8d191a 100644 --- a/src/main/java/de/pixart/messenger/Config.java +++ b/src/main/java/de/pixart/messenger/Config.java @@ -54,8 +54,6 @@ public final class Config { public static final boolean HIDE_MESSAGE_TEXT_IN_NOTIFICATION = false; public static final boolean SHOW_CONNECTED_ACCOUNTS = false; //show number of connected accounts in foreground notification - public static final boolean SHOW_DISABLE_FOREGROUND = false; //if set to true the foreground notification has a button to disable it - public static final boolean USE_ALWAYS_FOREGROUND = true; //if set to true the foreground service is always enabled public static final boolean ALWAYS_NOTIFY_BY_DEFAULT = false; diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index 5e86ebb91..f1a43dd28 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -625,13 +625,6 @@ public class NotificationService { return PendingIntent.getService(mXmppConnectionService, (conversation.getUuid().hashCode() % NOTIFICATION_ID_MULTIPLIER) + 16 * NOTIFICATION_ID_MULTIPLIER, intent, PendingIntent.FLAG_UPDATE_CURRENT); } - private PendingIntent createDisableForeground() { - final Intent intent = new Intent(mXmppConnectionService, - XmppConnectionService.class); - intent.setAction(XmppConnectionService.ACTION_DISABLE_FOREGROUND); - return PendingIntent.getService(mXmppConnectionService, 34, intent, 0); - } - private PendingIntent createTryAgainIntent() { final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class); intent.setAction(XmppConnectionService.ACTION_TRY_AGAIN); @@ -721,18 +714,6 @@ public class NotificationService { } else { mBuilder.setSmallIcon(R.drawable.ic_unlink_white_24dp); } - if (Config.SHOW_DISABLE_FOREGROUND && !Config.USE_ALWAYS_FOREGROUND) { - final int cancelIcon; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - mBuilder.setCategory(Notification.CATEGORY_SERVICE); - cancelIcon = R.drawable.ic_cancel_white_24dp; - } else { - cancelIcon = R.drawable.ic_action_cancel; - } - mBuilder.addAction(cancelIcon, - mXmppConnectionService.getString(R.string.disable_foreground_service), - createDisableForeground()); - } return mBuilder.build(); } @@ -748,7 +729,7 @@ public class NotificationService { errors.add(account); } } - if (Config.USE_ALWAYS_FOREGROUND) { + if (mXmppConnectionService.showForegroundService()) { notificationManager.notify(FOREGROUND_NOTIFICATION_ID, createForegroundNotification()); } final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService); 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); diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index 9c92c8be5..1f5395748 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -36,7 +36,6 @@ import de.pixart.messenger.xmpp.jid.Jid; public class SettingsActivity extends XmppActivity implements OnSharedPreferenceChangeListener { - public static final String KEEP_FOREGROUND_SERVICE = "keep_foreground_service"; public static final String AWAY_WHEN_SCREEN_IS_OFF = "away_when_screen_off"; public static final String TREAT_VIBRATE_AS_SILENT = "treat_vibrate_as_silent"; public static final String DND_ON_SILENT_MODE = "dnd_on_silent_mode"; @@ -46,6 +45,7 @@ public class SettingsActivity extends XmppActivity implements public static final String BROADCAST_LAST_ACTIVITY = "last_activity"; public static final String THEME = "theme"; public static final String SHOW_DYNAMIC_TAGS = "show_dynamic_tags"; + public static final String SHOW_FOREGROUND_SERVICE = "show_foreground_service"; public static final int REQUEST_WRITE_LOGS = 0xbf8701; private SettingsFragment mSettingsFragment; @@ -261,6 +261,8 @@ public class SettingsActivity extends XmppActivity implements } } } + } else if (name.equals(SHOW_FOREGROUND_SERVICE)) { + xmppConnectionService.toggleForegroundService(); } else if (resendPresence.contains(name)) { if (xmppConnectionServiceBound) { if (name.equals(AWAY_WHEN_SCREEN_IS_OFF) |