Removed auto keep alive adjust

This commit is contained in:
M66B 2019-07-08 19:23:07 +02:00
parent 381046d800
commit f62e1bce82
4 changed files with 1825 additions and 34 deletions

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 91,
version = 92,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -897,6 +897,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `folder` ADD COLUMN `selectable` INTEGER NOT NULL DEFAULT 1");
}
})
.addMigrations(new Migration(91, 92) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("UPDATE `account` SET poll_interval = 24");
}
})
.build();
}

View File

@ -48,7 +48,8 @@ import java.util.Objects;
public class EntityAccount extends EntityOrder implements Serializable {
static final String TABLE_NAME = "account";
static final int DEFAULT_KEEP_ALIVE_INTERVAL = 19; // minutes
// https://tools.ietf.org/html/rfc2177
static final int DEFAULT_KEEP_ALIVE_INTERVAL = 24; // minutes
@PrimaryKey(autoGenerate = true)
public Long id;

View File

@ -36,6 +36,7 @@ import android.os.Handler;
import android.os.PowerManager;
import androidx.annotation.Nullable;
import androidx.core.app.AlarmManagerCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleService;
@ -557,8 +558,6 @@ public class ServiceSynchronize extends LifecycleService {
final DB db = DB.getInstance(this);
int backoff = CONNECT_BACKOFF_START;
int poll_count = 0;
int poll_interval = account.poll_interval;
while (state.running()) {
state.reset();
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));
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) {
Log.i("Reporting sync error after=" + delayed);
Throwable warning = new Throwable(
@ -1100,26 +1099,10 @@ public class ServiceSynchronize extends LifecycleService {
while (state.running()) {
if (!state.recoverable())
throw new StoreClosedException(istore, "Unrecoverable");
// Sends store NOOP
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);
}
if (!istore.isConnected())
throw new StoreClosedException(istore, "NOOP");
}
for (EntityFolder folder : mapFolders.keySet())
if (folder.synchronize)
@ -1143,17 +1126,11 @@ public class ServiceSynchronize extends LifecycleService {
nm.cancel("receive:" + account.id, 1);
// Schedule keep alive alarm
EntityLog.log(this, account.name + " wait=" + poll_interval);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
am.set(
AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + poll_interval * 60 * 1000L,
pi);
else
am.setAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + poll_interval * 60 * 1000L,
pi);
EntityLog.log(this, account.name + " wait=" + account.poll_interval);
AlarmManagerCompat.setAndAllowWhileIdle(am,
AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + account.poll_interval * 60 * 1000L,
pi);
try {
wlAccount.release();