Fixed keep alive tuning

This commit is contained in:
M66B 2020-03-31 11:33:13 +02:00
parent b64ee170eb
commit 91fb1286a3
1 changed files with 8 additions and 3 deletions

View File

@ -1318,6 +1318,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
// Keep alive // Keep alive
boolean first = true; boolean first = true;
while (state.isRunning()) { while (state.isRunning()) {
long idleTime = state.getIdleTime();
try { try {
if (!state.isRecoverable()) if (!state.isRecoverable())
throw new StoreClosedException(iservice.getStore(), "Unrecoverable"); throw new StoreClosedException(iservice.getStore(), "Unrecoverable");
@ -1351,7 +1352,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (BuildConfig.DEBUG && if (BuildConfig.DEBUG &&
!first && !account.keep_alive_ok && !first && !account.keep_alive_ok &&
account.poll_interval > 9 && account.poll_interval > 9 &&
Math.abs(state.getIdleTime() - account.poll_interval * 60 * 1000L) < 60 * 1000L) { Math.abs(idleTime - account.poll_interval * 60 * 1000L) < 60 * 1000L) {
account.keep_alive_failed++; account.keep_alive_failed++;
if (account.keep_alive_failed >= 3) { if (account.keep_alive_failed >= 3) {
account.keep_alive_failed = 0; account.keep_alive_failed = 0;
@ -1362,7 +1363,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
EntityLog.log(ServiceSynchronize.this, account.name + EntityLog.log(ServiceSynchronize.this, account.name +
" keep alive failed=" + account.keep_alive_failed + " keep alive failed=" + account.keep_alive_failed +
" keep alive interval=" + account.poll_interval + " keep alive interval=" + account.poll_interval +
" max idle=" + state.getIdleTime()); " max idle=" + idleTime);
} }
throw ex; throw ex;
} }
@ -1370,9 +1371,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (BuildConfig.DEBUG && if (BuildConfig.DEBUG &&
!first && !account.keep_alive_ok && !first && !account.keep_alive_ok &&
account.poll_interval > 9 && account.poll_interval > 9 &&
Math.abs(state.getIdleTime() - account.poll_interval * 60 * 1000L) < 60 * 1000L) { Math.abs(idleTime - account.poll_interval * 60 * 1000L) < 60 * 1000L) {
account.keep_alive_ok = true; account.keep_alive_ok = true;
account.keep_alive_failed = 0;
db.account().setAccountKeepAliveOk(account.id, true); db.account().setAccountKeepAliveOk(account.id, true);
db.account().setAccountKeepAliveFailed(account.id, account.keep_alive_failed);
if (!BuildConfig.PLAY_STORE_RELEASE)
Log.e(account.host + " keep alive=" + account.poll_interval);
EntityLog.log(ServiceSynchronize.this, account.name + " keep alive ok"); EntityLog.log(ServiceSynchronize.this, account.name + " keep alive ok");
} }