1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-26 01:36:55 +00:00

Is transient account

This commit is contained in:
M66B 2020-10-26 11:47:42 +01:00
parent 8c8d3c8ddf
commit 5368501c95

View file

@ -947,7 +947,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
// Store NOOP // Store NOOP
//iservice.getStore().isConnected(); //iservice.getStore().isConnected();
if ("Still here".equals(message) && !account.ondemand) { if ("Still here".equals(message) && !isTransient(account)) {
long now = new Date().getTime(); long now = new Date().getTime();
if (now - start < STILL_THERE_THRESHOLD) if (now - start < STILL_THERE_THRESHOLD)
optimizeAccount(ServiceSynchronize.this, account, message); optimizeAccount(ServiceSynchronize.this, account, message);
@ -1253,8 +1253,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (sync && folder.selectable) if (sync && folder.selectable)
EntityOperation.sync(this, folder.id, false); EntityOperation.sync(this, folder.id, false);
} else } else {
mapFolders.put(folder, null); mapFolders.put(folder, null);
db.folder().setFolderState(folder.id, null);
}
} }
Log.i(account.name + " observing operations"); Log.i(account.name + " observing operations");
@ -1422,7 +1424,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
Log.w(folder.name, ex); Log.w(folder.name, ex);
} }
} }
if (folder.synchronize && (folder.poll || !capIdle)) if (!isTransient(account) &&
folder.synchronize && (folder.poll || !capIdle))
db.folder().setFolderState(folder.id, "waiting"); db.folder().setFolderState(folder.id, "waiting");
else else
db.folder().setFolderState(folder.id, null); db.folder().setFolderState(folder.id, null);
@ -1683,7 +1686,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
((ThreadPoolExecutor) executor).getQueue().clear(); ((ThreadPoolExecutor) executor).getQueue().clear();
// Close folders // Close folders
for (EntityFolder folder : mapFolders.keySet()) for (EntityFolder folder : mapFolders.keySet()) {
if (folder.synchronize && !folder.poll && mapFolders.get(folder) != null) { if (folder.synchronize && !folder.poll && mapFolders.get(folder) != null) {
db.folder().setFolderState(folder.id, "closing"); db.folder().setFolderState(folder.id, "closing");
try { try {
@ -1691,11 +1694,12 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
mapFolders.get(folder).close(); mapFolders.get(folder).close();
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
} finally {
db.folder().setFolderState(folder.id, null);
} }
} }
db.folder().setFolderState(folder.id, null);
}
// Close store // Close store
try { try {
db.account().setAccountState(account.id, "closing"); db.account().setAccountState(account.id, "closing");
@ -1739,7 +1743,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
// Cancel transient sync operations // Cancel transient sync operations
boolean enabled = prefs.getBoolean("enabled", true); boolean enabled = prefs.getBoolean("enabled", true);
int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL); int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL);
if (!enabled || account.ondemand || (pollInterval > 0 && !account.poll_exempted)) { if (isTransient(account)) {
List<EntityOperation> syncs = db.operation().getOperations(account.id, EntityOperation.SYNC); List<EntityOperation> syncs = db.operation().getOperations(account.id, EntityOperation.SYNC);
if (syncs != null) { if (syncs != null) {
for (EntityOperation op : syncs) { for (EntityOperation op : syncs) {
@ -1796,6 +1800,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} }
} }
private boolean isTransient(EntityAccount account) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean enabled = prefs.getBoolean("enabled", true);
int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL);
return (!enabled || account.ondemand || (pollInterval > 0 && !account.poll_exempted));
}
private void optimizeAccount(Context context, EntityAccount account, String reason) { private void optimizeAccount(Context context, EntityAccount account, String reason) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean auto_optimize = prefs.getBoolean("auto_optimize", false); boolean auto_optimize = prefs.getBoolean("auto_optimize", false);