Autofix too many simultaneous connections

pull/187/head
M66B 4 years ago
parent fffb5b2dba
commit c6243c1bd3

@ -206,7 +206,7 @@ public class EntityFolder extends EntityOrder implements Serializable {
static final int DEFAULT_KEEP = 30; // days
static final int DEFAULT_KEEP_DRAFTS = 180; // days
static final List<String> SYSTEM_FOLDER_SYNC = Collections.unmodifiableList(Arrays.asList(
private static final List<String> SYSTEM_FOLDER_SYNC = Collections.unmodifiableList(Arrays.asList(
INBOX,
DRAFTS,
SENT,
@ -214,7 +214,7 @@ public class EntityFolder extends EntityOrder implements Serializable {
TRASH,
JUNK
));
static final List<Boolean> SYSTEM_FOLDER_POLL = Collections.unmodifiableList(Arrays.asList(
private static final List<Boolean> SYSTEM_FOLDER_POLL = Collections.unmodifiableList(Arrays.asList(
false, // inbox
false, // drafts
false, // sent
@ -222,7 +222,7 @@ public class EntityFolder extends EntityOrder implements Serializable {
true, // trash
true // junk
)); // MUST match SYSTEM_FOLDER_SYNC
static final List<Boolean> SYSTEM_FOLDER_DOWNLOAD = Collections.unmodifiableList(Arrays.asList(
private static final List<Boolean> SYSTEM_FOLDER_DOWNLOAD = Collections.unmodifiableList(Arrays.asList(
true, // inbox
true, // drafts
false, // sent

@ -117,6 +117,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private static final int ACCOUNT_ERROR_AFTER = 60; // minutes
private static final int ACCOUNT_ERROR_AFTER_POLL = 4; // times
private static final int BACKOFF_ERROR_AFTER = 16; // seconds
private static final long AUTOFIX_TOO_MANY_FOLDERS = 3600 * 1000L; // milliseconds
private static final String ACTION_NEW_MESSAGE_COUNT = BuildConfig.APPLICATION_ID + ".NEW_MESSAGE_COUNT";
@ -1617,19 +1618,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
account.name + " " + Log.formatThrowable(ex, false));
db.account().setAccountError(account.id, Log.formatThrowable(ex));
boolean auto_optimize = prefs.getBoolean("auto_optimize", false);
if (auto_optimize && ConnectionHelper.isMaxConnections(ex)) {
for (int i = 0; i < EntityFolder.SYSTEM_FOLDER_SYNC.size(); i++)
if (EntityFolder.SYSTEM_FOLDER_POLL.get(i)) {
String ft = EntityFolder.SYSTEM_FOLDER_SYNC.get(i);
EntityFolder f = db.folder().getFolderByType(account.id, ft);
if (f != null && f.synchronize) {
EntityLog.log(ServiceSynchronize.this, account.name + "/" + f.name + "=poll");
db.folder().setFolderPoll(f.id, true);
}
}
}
// Report account connection error
if (account.last_connected != null && !ConnectionHelper.airplaneMode(this)) {
EntityLog.log(this, account.name + " last connected: " + new Date(account.last_connected));
@ -1746,6 +1734,36 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
state.setBackoff(backoff * 60);
}
}
// Autofix too many simultaneous connections
if (ConnectionHelper.isMaxConnections(last_fail)) {
boolean auto_optimize = prefs.getBoolean("auto_optimize", false);
if (auto_optimize ||
account.last_connected == null ||
now - account.last_connected > AUTOFIX_TOO_MANY_FOLDERS) {
int user = 0;
int system = 0;
List<EntityFolder> folders = db.folder().getFolders(account.id, false, true);
if (folders != null) {
for (EntityFolder folder : folders)
if (folder.synchronize && !folder.poll && EntityFolder.USER.equals(folder.type)) {
user++;
db.folder().setFolderPoll(folder.id, true);
}
if (user == 0)
for (EntityFolder folder : folders)
if (folder.synchronize && !folder.poll && !EntityFolder.INBOX.equals(folder.type)) {
system++;
db.folder().setFolderPoll(folder.id, true);
}
}
if (user > 0 || system > 0) {
Log.e("Autofix user=" + user + " system=" + system + " host=" + account.host);
EntityLog.log(this, account.name + " set poll user=" + user + " system=" + system);
}
}
}
}
}
} else {

Loading…
Cancel
Save