Added account option for IMAP IDLE restart

This commit is contained in:
M66B
2022-09-03 11:22:44 +02:00
parent d51ffd7972
commit 1b382c3fcc
11 changed files with 2854 additions and 6 deletions

View File

@@ -72,7 +72,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 242,
version = 243,
entities = {
EntityIdentity.class,
EntityAccount.class,
@@ -2450,13 +2450,20 @@ public abstract class DB extends RoomDatabase {
db.execSQL("DROP VIEW `folder_view`");
db.execSQL("CREATE VIEW IF NOT EXISTS `folder_view` AS " + TupleFolderView.query);
}
}).addMigrations(new Migration(241, 242) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `unicode` INTEGER NOT NULL DEFAULT 0");
}
}).addMigrations(new Migration(242, 243) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `keep_alive_noop` INTEGER NOT NULL DEFAULT 0");
db.execSQL("UPDATE account SET keep_alive_noop = 1" +
" WHERE host = 'outlook.office365.com' AND pop = " + EntityAccount.TYPE_IMAP);
}
}).addMigrations(new Migration(998, 999) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {

View File

@@ -84,6 +84,7 @@ public class EmailProvider implements Parcelable {
public int order;
public String type;
public int keepalive;
public boolean noop;
public boolean partial;
public boolean useip;
public boolean appPassword;
@@ -236,6 +237,7 @@ public class EmailProvider implements Parcelable {
provider.order = getAttributeIntValue(xml, "order", Integer.MAX_VALUE);
provider.keepalive = getAttributeIntValue(xml, "keepalive", 0);
provider.noop = getAttributeBooleanValue(xml, "noop", false);
provider.partial = getAttributeBooleanValue(xml, "partial", true);
provider.useip = getAttributeBooleanValue(xml, "useip", true);
provider.appPassword = getAttributeBooleanValue(xml, "appPassword", false);

View File

@@ -130,6 +130,8 @@ public class EntityAccount extends EntityOrder implements Serializable {
@NonNull
public Integer poll_interval = DEFAULT_KEEP_ALIVE_INTERVAL;
@NonNull
public Boolean keep_alive_noop = false;
@NonNull
public Boolean keep_alive_ok = false;
@NonNull
public Integer keep_alive_failed = 0;

View File

@@ -122,6 +122,7 @@ public class FragmentAccount extends FragmentBase {
private CheckBox cbBrowse;
private CheckBox cbAutoSeen;
private EditText etInterval;
private CheckBox cbNoop;
private CheckBox cbPartialFetch;
private CheckBox cbIgnoreSize;
private RadioGroup rgDate;
@@ -233,6 +234,7 @@ public class FragmentAccount extends FragmentBase {
cbBrowse = view.findViewById(R.id.cbBrowse);
cbAutoSeen = view.findViewById(R.id.cbAutoSeen);
etInterval = view.findViewById(R.id.etInterval);
cbNoop = view.findViewById(R.id.cbNoop);
cbPartialFetch = view.findViewById(R.id.cbPartialFetch);
cbIgnoreSize = view.findViewById(R.id.cbIgnoreSize);
rgDate = view.findViewById(R.id.rgDate);
@@ -313,6 +315,7 @@ public class FragmentAccount extends FragmentBase {
etName.setText(position > 1 ? provider.name : null);
etInterval.setText(provider.keepalive > 0 ? Integer.toString(provider.keepalive) : null);
cbNoop.setChecked(provider.noop);
cbPartialFetch.setChecked(provider.partial);
tvSentWarning.setVisibility(View.GONE);
@@ -899,6 +902,7 @@ public class FragmentAccount extends FragmentBase {
args.putBoolean("browse", cbBrowse.isChecked());
args.putBoolean("auto_seen", cbAutoSeen.isChecked());
args.putString("interval", etInterval.getText().toString());
args.putBoolean("noop", cbNoop.isChecked());
args.putBoolean("partial_fetch", cbPartialFetch.isChecked());
args.putBoolean("ignore_size", cbIgnoreSize.isChecked());
args.putBoolean("use_date", rgDate.getCheckedRadioButtonId() == R.id.radio_date_header);
@@ -971,6 +975,7 @@ public class FragmentAccount extends FragmentBase {
boolean browse = args.getBoolean("browse");
boolean auto_seen = args.getBoolean("auto_seen");
String interval = args.getString("interval");
boolean noop = args.getBoolean("noop");
boolean partial_fetch = args.getBoolean("partial_fetch");
boolean ignore_size = args.getBoolean("ignore_size");
boolean use_date = args.getBoolean("use_date");
@@ -1075,6 +1080,8 @@ public class FragmentAccount extends FragmentBase {
return true;
if (!Objects.equals(account.poll_interval, poll_interval))
return true;
if (!Objects.equals(account.keep_alive_noop, noop))
return true;
if (!Objects.equals(account.partial_fetch, partial_fetch))
return true;
if (!Objects.equals(account.ignore_size, ignore_size))
@@ -1222,7 +1229,7 @@ public class FragmentAccount extends FragmentBase {
account.keep_alive_succeeded = 0;
}
account.poll_interval = Math.max(1, poll_interval);
account.keep_alive_noop = noop;
account.partial_fetch = partial_fetch;
account.ignore_size = ignore_size;
account.use_date = use_date;
@@ -1588,6 +1595,7 @@ public class FragmentAccount extends FragmentBase {
cbBrowse.setChecked(account == null ? true : account.browse);
cbAutoSeen.setChecked(account == null ? true : account.auto_seen);
etInterval.setText(account == null ? "" : Long.toString(account.poll_interval));
cbNoop.setChecked(account == null ? true : account.keep_alive_noop);
cbPartialFetch.setChecked(account == null ? true : account.partial_fetch);
cbIgnoreSize.setChecked(account == null ? false : account.ignore_size);
cbUnicode.setChecked(account == null ? false : account.unicode);

View File

@@ -863,6 +863,7 @@ public class FragmentOAuth extends FragmentBase {
if (provider.keepalive > 0)
account.poll_interval = provider.keepalive;
account.keep_alive_noop = provider.noop;
account.partial_fetch = provider.partial;

View File

@@ -535,6 +535,7 @@ public class FragmentQuickSetup extends FragmentBase {
if (provider.keepalive > 0)
account.poll_interval = provider.keepalive;
account.keep_alive_noop = provider.noop;
account.partial_fetch = provider.partial;

View File

@@ -1518,7 +1518,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (account.protocol != EntityAccount.TYPE_IMAP)
iservice.setLeaveOnServer(account.leave_on_server);
if ("outlook.office365.com".equalsIgnoreCase(account.host)) {
if (account.keep_alive_noop) {
int timeout = prefs.getInt("timeout", EmailService.DEFAULT_CONNECT_TIMEOUT);
iservice.setRestartIdleInterval(timeout * 2 * 6); // 20 x 2 x 6 = 4 min
}