Show backoff time

pull/187/head
M66B 4 years ago
parent 1f9232bb1e
commit d3806b8eb1

File diff suppressed because it is too large Load Diff

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

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

@ -143,6 +143,9 @@ public interface DaoAccount {
@Query("UPDATE account SET last_connected = :last_connected WHERE id = :id") @Query("UPDATE account SET last_connected = :last_connected WHERE id = :id")
int setAccountConnected(long id, long last_connected); 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") @Query("UPDATE account SET quota_usage = :used, quota_limit = :limit WHERE id = :id")
int setAccountQuota(long id, Long used, Long limit); int setAccountQuota(long id, Long used, Long limit);

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

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

@ -152,7 +152,7 @@
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
android:ellipsize="start" android:ellipsize="start"
android:singleLine="true" android:singleLine="true"
android:text="Last connected time" android:text="@string/title_last_connected"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toStartOf="@id/tvUsage" app:layout_constraintEnd_toStartOf="@id/tvUsage"
app:layout_constraintStart_toEndOf="@+id/ivState" app:layout_constraintStart_toEndOf="@+id/ivState"
@ -170,6 +170,20 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvHost" /> app:layout_constraintTop_toBottomOf="@id/tvHost" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvBackoff"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:ellipsize="start"
android:singleLine="true"
android:text="@string/title_backoff_until"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/ivState"
app:layout_constraintTop_toBottomOf="@id/tvLast" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvQuota" android:id="@+id/tvQuota"
android:layout_width="0dp" android:layout_width="0dp"
@ -182,7 +196,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toStartOf="@+id/tvMaxSize" app:layout_constraintEnd_toStartOf="@+id/tvMaxSize"
app:layout_constraintStart_toEndOf="@+id/ivState" app:layout_constraintStart_toEndOf="@+id/ivState"
app:layout_constraintTop_toBottomOf="@id/tvLast" /> app:layout_constraintTop_toBottomOf="@id/tvBackoff" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvMaxSize" android:id="@+id/tvMaxSize"
@ -195,7 +209,7 @@
android:text="25 MB" android:text="25 MB"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvLast" /> app:layout_constraintTop_toBottomOf="@id/tvBackoff" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvIdentity" android:id="@+id/tvIdentity"

@ -700,6 +700,7 @@
<string name="title_edit_html">Edit as HTML</string> <string name="title_edit_html">Edit as HTML</string>
<string name="title_sign_key">Sign key: %1$s</string> <string name="title_sign_key">Sign key: %1$s</string>
<string name="title_last_connected">Last connected: %1$s</string> <string name="title_last_connected">Last connected: %1$s</string>
<string name="title_backoff_until">Waiting until: %1$s</string>
<string name="title_storage_quota">Server storage usage: %1$s/%2$s</string> <string name="title_storage_quota">Server storage usage: %1$s/%2$s</string>
<string name="title_pop_support">The POP3 protocol supports downloading and deleting messages from the inbox only. POP3 cannot mark messages as read, move messages, etc. POP3 will use more battery power and data than IMAP. So, consider using the IMAP protocol whenever possible.</string> <string name="title_pop_support">The POP3 protocol supports downloading and deleting messages from the inbox only. POP3 cannot mark messages as read, move messages, etc. POP3 will use more battery power and data than IMAP. So, consider using the IMAP protocol whenever possible.</string>
<string name="title_oauth_support">OAuth is not supported</string> <string name="title_oauth_support">OAuth is not supported</string>

Loading…
Cancel
Save