Auto optimize no IDLE

pull/175/head
M66B 5 years ago
parent 4a8bf5fe19
commit 7ca3415fbd

@ -848,29 +848,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if ("Still here".equals(message) && !account.ondemand) { if ("Still here".equals(message) && !account.ondemand) {
long now = new Date().getTime(); long now = new Date().getTime();
if (now - start > STILL_THERE_THRESHOLD) if (now - start < STILL_THERE_THRESHOLD)
return; optimizeAccount(ServiceSynchronize.this, account, message);
boolean auto_optimize = prefs.getBoolean("auto_optimize", false);
if (!auto_optimize)
return;
int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL);
if (pollInterval == 0) {
prefs.edit().putInt("poll_interval", STILL_THERE_POLL_INTERVAL).apply();
try {
db.beginTransaction();
for (EntityAccount a : db.account().getAccounts())
db.account().setAccountPollExempted(a.id, !a.id.equals(account.id));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
ServiceSynchronize.eval(ServiceSynchronize.this, message);
} else if (account.poll_exempted) {
db.account().setAccountPollExempted(account.id, false);
ServiceSynchronize.eval(ServiceSynchronize.this, message);
}
} }
} else } else
try { try {
@ -964,6 +943,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
final boolean capIdle = iservice.hasCapability("IDLE"); final boolean capIdle = iservice.hasCapability("IDLE");
Log.i(account.name + " idle=" + capIdle); Log.i(account.name + " idle=" + capIdle);
if (!capIdle)
optimizeAccount(ServiceSynchronize.this, account, "IDLE");
db.account().setAccountState(account.id, "connected"); db.account().setAccountState(account.id, "connected");
db.account().setAccountError(account.id, null); db.account().setAccountError(account.id, null);
@ -1598,6 +1579,32 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
message.contains("User is authenticated but not connected") /* Outlook */)); message.contains("User is authenticated but not connected") /* Outlook */));
} }
private void optimizeAccount(Context context, EntityAccount account, String reason) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean auto_optimize = prefs.getBoolean("auto_optimize", false);
if (!auto_optimize)
return;
DB db = DB.getInstance(context);
int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL);
if (pollInterval == 0) {
prefs.edit().putInt("poll_interval", STILL_THERE_POLL_INTERVAL).apply();
try {
db.beginTransaction();
for (EntityAccount a : db.account().getAccounts())
db.account().setAccountPollExempted(a.id, !a.id.equals(account.id));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
ServiceSynchronize.eval(ServiceSynchronize.this, "Optimize=" + reason);
} else if (account.poll_exempted) {
db.account().setAccountPollExempted(account.id, false);
ServiceSynchronize.eval(ServiceSynchronize.this, "Optimize=" + reason);
}
}
private ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() { private ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
@Override @Override
public void onAvailable(@NonNull Network network) { public void onAvailable(@NonNull Network network) {

Loading…
Cancel
Save