removed unnecessary push_mode

This commit is contained in:
Daniel Gultsch 2016-11-02 11:04:33 +01:00
parent e582b9fc10
commit 544c5b4a21
3 changed files with 10 additions and 37 deletions

View file

@ -61,11 +61,6 @@ public final class Config {
public static final int CONNECT_DISCO_TIMEOUT = 20; public static final int CONNECT_DISCO_TIMEOUT = 20;
public static final int MINI_GRACE_PERIOD = 750; public static final int MINI_GRACE_PERIOD = 750;
public static final boolean PUSH_MODE = false; //closes the tcp connection when going to background
//and after PING_MIN_INTERVAL of inactivity
//very experimental. only enable this if you want
//to around with GCM push
public static final int AVATAR_SIZE = 192; public static final int AVATAR_SIZE = 192;
public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.WEBP; public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.WEBP;

View file

@ -19,9 +19,6 @@ public class EventReceiver extends BroadcastReceiver {
mIntentForService.setAction("other"); mIntentForService.setAction("other");
} }
final String action = intent.getAction(); final String action = intent.getAction();
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION) && Config.PUSH_MODE) {
return;
}
if (action.equals("ui") || DatabaseBackend.getInstance(context).hasEnabledAccounts()) { if (action.equals("ui") || DatabaseBackend.getInstance(context).hasEnabledAccounts()) {
context.startService(mIntentForService); context.startService(mIntentForService);
} }

View file

@ -331,16 +331,10 @@ public class XmppConnectionService extends Service {
joinMuc(conversation); joinMuc(conversation);
} }
account.pendingConferenceJoins.clear(); account.pendingConferenceJoins.clear();
scheduleWakeUpCall(Config.PUSH_MODE ? Config.PING_MIN_INTERVAL : Config.PING_MAX_INTERVAL, account.getUuid().hashCode()); scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode());
} else if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED) { } else if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED) {
resetSendingToWaiting(account); resetSendingToWaiting(account);
final boolean disabled = account.isOptionSet(Account.OPTION_DISABLED); if (!account.isOptionSet(Account.OPTION_DISABLED)) {
final boolean listeners = checkListeners();
final boolean pushMode = Config.PUSH_MODE
&& mPushManagementService.available(account)
&& listeners;
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": push mode="+Boolean.toString(pushMode)+" listeners="+Boolean.toString(listeners));
if (!disabled && !pushMode) {
synchronized (mLowPingTimeoutMode) { synchronized (mLowPingTimeoutMode) {
if (mLowPingTimeoutMode.contains(account.getJid().toBareJid())) { if (mLowPingTimeoutMode.contains(account.getJid().toBareJid())) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": went into offline state during low ping mode. reconnecting now"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": went into offline state during low ping mode. reconnecting now");
@ -604,8 +598,7 @@ public class XmppConnectionService extends Service {
refreshAllGcmTokens(); refreshAllGcmTokens();
break; break;
case ACTION_IDLE_PING: case ACTION_IDLE_PING:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
&& !Config.PUSH_MODE) {
scheduleNextIdlePing(); scheduleNextIdlePing();
} }
break; break;
@ -638,7 +631,7 @@ public class XmppConnectionService extends Service {
synchronized (mLowPingTimeoutMode) { synchronized (mLowPingTimeoutMode) {
long lastReceived = account.getXmppConnection().getLastPacketReceived(); long lastReceived = account.getXmppConnection().getLastPacketReceived();
long lastSent = account.getXmppConnection().getLastPingSent(); long lastSent = account.getXmppConnection().getLastPingSent();
long pingInterval = (Config.PUSH_MODE || "ui".equals(action)) ? Config.PING_MIN_INTERVAL * 1000 : Config.PING_MAX_INTERVAL * 1000; long pingInterval = "ui".equals(action) ? Config.PING_MIN_INTERVAL * 1000 : Config.PING_MAX_INTERVAL * 1000;
long msToNextPing = (Math.max(lastReceived, lastSent) + pingInterval) - SystemClock.elapsedRealtime(); long msToNextPing = (Math.max(lastReceived, lastSent) + pingInterval) - SystemClock.elapsedRealtime();
int pingTimeout = mLowPingTimeoutMode.contains(account.getJid().toBareJid()) ? Config.LOW_PING_TIMEOUT * 1000 : Config.PING_TIMEOUT * 1000; int pingTimeout = mLowPingTimeoutMode.contains(account.getJid().toBareJid()) ? Config.LOW_PING_TIMEOUT * 1000 : Config.PING_TIMEOUT * 1000;
long pingTimeoutIn = (lastSent + pingTimeout) - SystemClock.elapsedRealtime(); long pingTimeoutIn = (lastSent + pingTimeout) - SystemClock.elapsedRealtime();
@ -696,23 +689,15 @@ public class XmppConnectionService extends Service {
} }
} }
if (pingNow) { if (pingNow) {
final boolean listeners = checkListeners();
for (Account account : pingCandidates) { for (Account account : pingCandidates) {
if (listeners
&& Config.PUSH_MODE
&& mPushManagementService.available(account)) {
account.getXmppConnection().waitForPush();
cancelWakeUpCall(account.getUuid().hashCode());
} else {
synchronized (mLowPingTimeoutMode) { synchronized (mLowPingTimeoutMode) {
final boolean lowTimeout = mLowPingTimeoutMode.contains(account.getJid().toBareJid()); final boolean lowTimeout = mLowPingTimeoutMode.contains(account.getJid().toBareJid());
account.getXmppConnection().sendPing(); account.getXmppConnection().sendPing();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping (action=" + action + ",listeners=" + Boolean.toString(listeners) + ",lowTimeout=" + Boolean.toString(lowTimeout) + ")"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping (action=" + action + ",lowTimeout=" + Boolean.toString(lowTimeout) + ")");
scheduleWakeUpCall(lowTimeout ? Config.LOW_PING_TIMEOUT : Config.PING_TIMEOUT, account.getUuid().hashCode()); scheduleWakeUpCall(lowTimeout ? Config.LOW_PING_TIMEOUT : Config.PING_TIMEOUT, account.getUuid().hashCode());
} }
} }
} }
}
if (wakeLock.isHeld()) { if (wakeLock.isHeld()) {
try { try {
wakeLock.release(); wakeLock.release();
@ -912,7 +897,7 @@ public class XmppConnectionService extends Service {
toggleForegroundService(); toggleForegroundService();
updateUnreadCountBadge(); updateUnreadCountBadge();
toggleScreenEventReceiver(); toggleScreenEventReceiver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Config.PUSH_MODE) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
scheduleNextIdlePing(); scheduleNextIdlePing();
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@ -2023,10 +2008,6 @@ public class XmppConnectionService extends Service {
if (connection.getFeatures().csi()) { if (connection.getFeatures().csi()) {
connection.sendInactive(); connection.sendInactive();
} }
if (Config.PUSH_MODE && mPushManagementService.available(account)) {
connection.waitForPush();
cancelWakeUpCall(account.getUuid().hashCode());
}
} }
} }
} }