Show backoff time

This commit is contained in:
M66B
2020-10-29 20:03:09 +01:00
parent 1f9232bb1e
commit d3806b8eb1
8 changed files with 2360 additions and 4 deletions

View File

@@ -96,6 +96,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
private TextView tvHost;
private TextView tvLast;
private TextView tvUsage;
private TextView tvBackoff;
private TextView tvQuota;
private TextView tvMaxSize;
private TextView tvIdentity;
@@ -123,6 +124,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
tvHost = itemView.findViewById(R.id.tvHost);
tvLast = itemView.findViewById(R.id.tvLast);
tvUsage = itemView.findViewById(R.id.tvUsage);
tvBackoff = itemView.findViewById(R.id.tvBackoff);
tvQuota = itemView.findViewById(R.id.tvQuota);
tvMaxSize = itemView.findViewById(R.id.tvMaxSize);
tvIdentity = itemView.findViewById(R.id.tvIdentity);
@@ -197,9 +199,15 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
"/" + account.keep_alive_ok +
"/" + account.keep_alive_failed +
"/" + account.keep_alive_succeeded : "")));
tvBackoff.setText(context.getString(R.string.title_backoff_until,
account.backoff_until == null ? "-" : DTF.format(account.backoff_until)));
tvBackoff.setVisibility(account.backoff_until == null && !BuildConfig.DEBUG ? View.GONE : View.VISIBLE);
Integer percent = null;
if (!settings && account.quota_usage != null && account.quota_limit != null)
percent = Math.round((float) account.quota_usage * 100 / account.quota_limit);
tvUsage.setText(percent == null ? null : NF.format(percent) + "%");
tvUsage.setVisibility(percent == null ? View.GONE : View.VISIBLE);
tvQuota.setText(context.getString(R.string.title_storage_quota,

View File

@@ -64,7 +64,7 @@ import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 176,
version = 177,
entities = {
EntityIdentity.class,
EntityAccount.class,
@@ -1731,6 +1731,13 @@ public abstract class DB extends RoomDatabase {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `auto_submitted` INTEGER");
}
})
.addMigrations(new Migration(176, 177) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `backoff_until` INTEGER");
}
});
}

View File

@@ -143,6 +143,9 @@ public interface DaoAccount {
@Query("UPDATE account SET last_connected = :last_connected WHERE id = :id")
int setAccountConnected(long id, long last_connected);
@Query("UPDATE account SET backoff_until = :backoff_until WHERE id = :id")
int setAccountBackoff(long id, Long backoff_until);
@Query("UPDATE account SET quota_usage = :used, quota_limit = :limit WHERE id = :id")
int setAccountQuota(long id, Long used, Long limit);

View File

@@ -142,6 +142,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
public String warning;
public String error;
public Long last_connected;
public Long backoff_until;
public Long max_size;
boolean isGmail() {
@@ -367,6 +368,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
Objects.equals(this.warning, other.warning) &&
Objects.equals(this.error, other.error) &&
Objects.equals(this.last_connected, other.last_connected) &&
Objects.equals(this.backoff_until, other.backoff_until) &&
Objects.equals(this.max_size, other.max_size));
} else
return false;

View File

@@ -1739,9 +1739,12 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (backoff <= max) {
// Short back-off period, keep device awake
try {
db.account().setAccountBackoff(account.id, System.currentTimeMillis() + backoff * 1000L);
state.acquire(backoff * 1000L, true);
} catch (InterruptedException ex) {
Log.w(account.name + " backoff " + ex.toString());
} finally {
db.account().setAccountBackoff(account.id, null);
}
} else {
// Cancel transient sync operations
@@ -1769,6 +1772,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, trigger, pi);
try {
db.account().setAccountBackoff(account.id, trigger);
wlAccount.release();
state.acquire(2 * backoff * 1000L, true);
Log.i("### " + account.name + " backoff done");
@@ -1776,6 +1780,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
Log.w(account.name + " backoff " + ex.toString());
} finally {
wlAccount.acquire();
db.account().setAccountBackoff(account.id, null);
}
} finally {
am.cancel(pi);