|
|
@ -36,6 +36,7 @@ import android.os.Handler;
|
|
|
|
import android.os.PowerManager;
|
|
|
|
import android.os.PowerManager;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
|
|
import androidx.core.app.AlarmManagerCompat;
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.lifecycle.LifecycleService;
|
|
|
|
import androidx.lifecycle.LifecycleService;
|
|
|
@ -557,8 +558,6 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
final DB db = DB.getInstance(this);
|
|
|
|
final DB db = DB.getInstance(this);
|
|
|
|
|
|
|
|
|
|
|
|
int backoff = CONNECT_BACKOFF_START;
|
|
|
|
int backoff = CONNECT_BACKOFF_START;
|
|
|
|
int poll_count = 0;
|
|
|
|
|
|
|
|
int poll_interval = account.poll_interval;
|
|
|
|
|
|
|
|
while (state.running()) {
|
|
|
|
while (state.running()) {
|
|
|
|
state.reset();
|
|
|
|
state.reset();
|
|
|
|
Log.i(account.name + " run");
|
|
|
|
Log.i(account.name + " run");
|
|
|
@ -710,7 +709,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
EntityLog.log(this, account.name + " last connected: " + new Date(account.last_connected));
|
|
|
|
EntityLog.log(this, account.name + " last connected: " + new Date(account.last_connected));
|
|
|
|
|
|
|
|
|
|
|
|
long now = new Date().getTime();
|
|
|
|
long now = new Date().getTime();
|
|
|
|
long delayed = now - account.last_connected - poll_interval * 60 * 1000L;
|
|
|
|
long delayed = now - account.last_connected - account.poll_interval * 60 * 1000L;
|
|
|
|
if (delayed > ACCOUNT_ERROR_AFTER * 60 * 1000L && backoff > BACKOFF_ERROR_AFTER) {
|
|
|
|
if (delayed > ACCOUNT_ERROR_AFTER * 60 * 1000L && backoff > BACKOFF_ERROR_AFTER) {
|
|
|
|
Log.i("Reporting sync error after=" + delayed);
|
|
|
|
Log.i("Reporting sync error after=" + delayed);
|
|
|
|
Throwable warning = new Throwable(
|
|
|
|
Throwable warning = new Throwable(
|
|
|
@ -1100,26 +1099,10 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
while (state.running()) {
|
|
|
|
while (state.running()) {
|
|
|
|
if (!state.recoverable())
|
|
|
|
if (!state.recoverable())
|
|
|
|
throw new StoreClosedException(istore, "Unrecoverable");
|
|
|
|
throw new StoreClosedException(istore, "Unrecoverable");
|
|
|
|
|
|
|
|
|
|
|
|
// Sends store NOOP
|
|
|
|
// Sends store NOOP
|
|
|
|
if (istore.isConnected()) {
|
|
|
|
if (!istore.isConnected())
|
|
|
|
poll_count++;
|
|
|
|
|
|
|
|
EntityLog.log(this, account.name + " poll count=" + poll_count);
|
|
|
|
|
|
|
|
if (capIdle && poll_count >= 3 && poll_interval != account.poll_interval) {
|
|
|
|
|
|
|
|
Log.w(account.host + " keep alive " + account.poll_interval + " > " + poll_interval);
|
|
|
|
|
|
|
|
EntityLog.log(this, account.name + " adjusting keep alive interval" +
|
|
|
|
|
|
|
|
" from " + account.poll_interval + " to " + poll_interval);
|
|
|
|
|
|
|
|
db.account().setAccountPollInterval(account.id, poll_interval);
|
|
|
|
|
|
|
|
account.poll_interval = poll_interval;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
poll_count = 0;
|
|
|
|
|
|
|
|
if (capIdle && poll_interval > 9) {
|
|
|
|
|
|
|
|
poll_interval -= Math.ceil(poll_interval * 0.1f);
|
|
|
|
|
|
|
|
EntityLog.log(this, account.name + " decreased keep alive interval" +
|
|
|
|
|
|
|
|
" to " + poll_interval);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new StoreClosedException(istore, "NOOP");
|
|
|
|
throw new StoreClosedException(istore, "NOOP");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (EntityFolder folder : mapFolders.keySet())
|
|
|
|
for (EntityFolder folder : mapFolders.keySet())
|
|
|
|
if (folder.synchronize)
|
|
|
|
if (folder.synchronize)
|
|
|
@ -1143,17 +1126,11 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
nm.cancel("receive:" + account.id, 1);
|
|
|
|
nm.cancel("receive:" + account.id, 1);
|
|
|
|
|
|
|
|
|
|
|
|
// Schedule keep alive alarm
|
|
|
|
// Schedule keep alive alarm
|
|
|
|
EntityLog.log(this, account.name + " wait=" + poll_interval);
|
|
|
|
EntityLog.log(this, account.name + " wait=" + account.poll_interval);
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
|
|
|
AlarmManagerCompat.setAndAllowWhileIdle(am,
|
|
|
|
am.set(
|
|
|
|
AlarmManager.RTC_WAKEUP,
|
|
|
|
AlarmManager.RTC_WAKEUP,
|
|
|
|
System.currentTimeMillis() + account.poll_interval * 60 * 1000L,
|
|
|
|
System.currentTimeMillis() + poll_interval * 60 * 1000L,
|
|
|
|
pi);
|
|
|
|
pi);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
am.setAndAllowWhileIdle(
|
|
|
|
|
|
|
|
AlarmManager.RTC_WAKEUP,
|
|
|
|
|
|
|
|
System.currentTimeMillis() + poll_interval * 60 * 1000L,
|
|
|
|
|
|
|
|
pi);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
wlAccount.release();
|
|
|
|
wlAccount.release();
|
|
|
|