|
|
|
@ -21,10 +21,6 @@ package eu.faircode.email;
|
|
|
|
|
|
|
|
|
|
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
|
|
|
|
|
|
|
|
|
|
import static eu.faircode.email.EntityLog.LOG_ACCOUNT;
|
|
|
|
|
import static eu.faircode.email.EntityLog.LOG_NETWORK;
|
|
|
|
|
import static eu.faircode.email.EntityLog.LOG_SCHEDULE;
|
|
|
|
|
|
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
@ -277,7 +273,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
int index = accountStates.indexOf(current);
|
|
|
|
|
if (index < 0) {
|
|
|
|
|
if (current.canRun()) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### new " + current +
|
|
|
|
|
" force=" + force +
|
|
|
|
|
" start=" + current.canRun() +
|
|
|
|
@ -313,7 +309,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
prev.canRun() != current.canRun() ||
|
|
|
|
|
!prev.accountState.equals(current.accountState)) {
|
|
|
|
|
if (prev.canRun() || current.canRun())
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### changed " + current +
|
|
|
|
|
" reload=" + reload +
|
|
|
|
|
" force=" + force +
|
|
|
|
@ -342,7 +338,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
if (state != null) {
|
|
|
|
|
Network p = prev.networkState.getActive();
|
|
|
|
|
if (p != null && !p.equals(current.networkState.getActive())) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### changed " + current +
|
|
|
|
|
" active=" + prev.networkState.getActive() + "/" + current.networkState.getActive());
|
|
|
|
|
state.error(new OperationCanceledException("Active network changed"));
|
|
|
|
@ -361,7 +357,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
|
|
|
|
|
if (event) {
|
|
|
|
|
lastEventId++;
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### eventId=" + lastEventId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -402,7 +398,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!runService && lastQuitId != lastEventId) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### quitting" +
|
|
|
|
|
" run=" + runService +
|
|
|
|
|
" startId=" + lastQuitId + "/" + lastEventId);
|
|
|
|
@ -416,7 +412,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
queue.submit(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### init " + accountNetworkState);
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(ServiceSynchronize.this);
|
|
|
|
@ -445,7 +441,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void start(final TupleAccountNetworkState accountNetworkState, boolean sync, boolean force) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"Service start=" + accountNetworkState + " sync=" + sync + " force=" + force);
|
|
|
|
|
|
|
|
|
|
final Core.State astate = new Core.State(accountNetworkState.networkState);
|
|
|
|
@ -476,7 +472,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
|
|
|
|
|
Log.i("### start=" + accountNetworkState + " sync=" + sync);
|
|
|
|
|
astate.start();
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### started=" + accountNetworkState);
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.e(ex);
|
|
|
|
@ -491,7 +487,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
return;
|
|
|
|
|
coreStates.remove(accountNetworkState.accountState.id);
|
|
|
|
|
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"Service stop=" + accountNetworkState);
|
|
|
|
|
|
|
|
|
|
queue.submit(new Runnable() {
|
|
|
|
@ -511,7 +507,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
db.account().setAccountThread(accountNetworkState.accountState.id, null);
|
|
|
|
|
state.stop();
|
|
|
|
|
state.join();
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### stopped=" + accountNetworkState);
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.e(ex);
|
|
|
|
@ -521,7 +517,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void delete(final TupleAccountNetworkState accountNetworkState) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"Service delete=" + accountNetworkState);
|
|
|
|
|
|
|
|
|
|
queue.submit(new Runnable() {
|
|
|
|
@ -547,7 +543,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### quit eventId=" + eventId);
|
|
|
|
|
|
|
|
|
|
if (eventId == null) {
|
|
|
|
@ -569,7 +565,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!eventId.equals(lastEventId)) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### quit cancelled eventId=" + eventId + "/" + lastEventId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -577,7 +573,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
|
|
|
|
|
// Stop service
|
|
|
|
|
stopSelf();
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### stop self eventId=" + eventId);
|
|
|
|
|
|
|
|
|
|
WorkerCleanup.cleanupConditionally(ServiceSynchronize.this);
|
|
|
|
@ -816,7 +812,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
|
|
String action = (intent == null ? null : intent.getAction());
|
|
|
|
|
String reason = (intent == null ? null : intent.getStringExtra("reason"));
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### Service command " + intent +
|
|
|
|
|
" action=" + action + " reason=" + reason);
|
|
|
|
|
Log.logExtras(intent);
|
|
|
|
@ -917,13 +913,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
Core.State state = coreStates.get(account);
|
|
|
|
|
|
|
|
|
|
if (state == null)
|
|
|
|
|
EntityLog.log(this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### wakeup missing account=" + account);
|
|
|
|
|
else {
|
|
|
|
|
EntityLog.log(this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### waking up account=" + account);
|
|
|
|
|
if (!state.release())
|
|
|
|
|
EntityLog.log(this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Scheduling,
|
|
|
|
|
"### waking up failed account=" + account);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -961,7 +957,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
EntityOperation.queue(ServiceSynchronize.this, message, EntityOperation.SEND);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
|
|
|
|
folder.name + " Unsnooze" +
|
|
|
|
|
" id=" + message.id +
|
|
|
|
|
" ui_seen=" + message.ui_seen + "" +
|
|
|
|
@ -1131,7 +1127,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onWatchdog(Intent intent) {
|
|
|
|
|
EntityLog.log(this, LOG_SCHEDULE, "Watchdog");
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Scheduling, "Watchdog");
|
|
|
|
|
schedule(this, false);
|
|
|
|
|
|
|
|
|
|
if (lastNetworkState == null || !lastNetworkState.isSuitable())
|
|
|
|
@ -1281,7 +1277,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
if (TextUtils.isEmpty(message))
|
|
|
|
|
message = "?";
|
|
|
|
|
if (e.getMessageType() == StoreEvent.NOTICE) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " notice: " + message);
|
|
|
|
|
|
|
|
|
|
if ("Still here".equals(message) &&
|
|
|
|
@ -1300,7 +1296,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
try {
|
|
|
|
|
wlFolder.acquire();
|
|
|
|
|
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " alert: " + message);
|
|
|
|
|
|
|
|
|
|
if (!ConnectionHelper.isMaxConnections(message))
|
|
|
|
@ -1322,7 +1318,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
List<Thread> idlers = new ArrayList<>();
|
|
|
|
|
try {
|
|
|
|
|
// Initiate connection
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " connecting");
|
|
|
|
|
db.folder().setFolderStates(account.id, null);
|
|
|
|
|
db.account().setAccountState(account.id, "connecting");
|
|
|
|
@ -1378,11 +1374,11 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
Store istore = iservice.getStore();
|
|
|
|
|
if (istore instanceof IMAPStore) {
|
|
|
|
|
Map<String, String> caps = ((IMAPStore) istore).getCapabilities();
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " connected" +
|
|
|
|
|
" caps=" + (caps == null ? null : TextUtils.join(" ", caps.keySet())));
|
|
|
|
|
} else
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " connected");
|
|
|
|
|
|
|
|
|
|
db.account().setAccountMaxSize(account.id, iservice.getMaxSize());
|
|
|
|
@ -1627,7 +1623,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
}
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.e(folder.name, ex);
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Account,
|
|
|
|
|
folder.name + " idle " + Log.formatThrowable(ex, false));
|
|
|
|
|
state.error(new FolderClosedException(ifolder, "IDLE", new Exception(ex)));
|
|
|
|
|
} finally {
|
|
|
|
@ -1870,7 +1866,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.e(folder.name, ex);
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Account,
|
|
|
|
|
folder.name + " process " + Log.formatThrowable(ex, false));
|
|
|
|
|
db.folder().setFolderError(folder.id, Log.formatThrowable(ex));
|
|
|
|
|
if (!(ex instanceof FolderNotFoundException))
|
|
|
|
@ -1909,7 +1905,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
!account.keep_alive_ok && account.poll_interval > 9 &&
|
|
|
|
|
Math.abs(idleTime - account.poll_interval * 60 * 1000L) < 60 * 1000L);
|
|
|
|
|
if (tune_keep_alive && !first && !account.keep_alive_ok)
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name +
|
|
|
|
|
" Tune interval=" + account.poll_interval +
|
|
|
|
|
" idle=" + idleTime + "/" + tune);
|
|
|
|
@ -1925,7 +1921,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
|
|
|
|
|
// Sends store NOOP
|
|
|
|
|
if (EmailService.SEPARATE_STORE_CONNECTION) {
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " checking store" +
|
|
|
|
|
" memory=" + Log.getFreeMemMb() +
|
|
|
|
|
" battery=" + Helper.getBatteryLevel(this));
|
|
|
|
@ -1941,7 +1937,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sync) {
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " checking folders");
|
|
|
|
|
for (EntityFolder folder : mapFolders.keySet())
|
|
|
|
|
if (folder.selectable && folder.synchronize)
|
|
|
|
@ -2006,7 +2002,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
|
|
|
|
|
// Record successful connection
|
|
|
|
|
account.last_connected = new Date().getTime();
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " set last_connected=" + new Date(account.last_connected));
|
|
|
|
|
db.account().setAccountConnected(account.id, account.last_connected);
|
|
|
|
|
db.account().setAccountWarning(account.id, capIdle ? null : getString(R.string.title_no_idle));
|
|
|
|
@ -2026,7 +2022,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
try {
|
|
|
|
|
long duration = account.poll_interval * 60 * 1000L;
|
|
|
|
|
long trigger = System.currentTimeMillis() + duration;
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
"### " + account.name + " keep alive" +
|
|
|
|
|
" wait=" + account.poll_interval + " until=" + new Date(trigger));
|
|
|
|
|
AlarmManagerCompatEx.setAndAllowWhileIdle(ServiceSynchronize.this, am, AlarmManager.RTC_WAKEUP, trigger, pi);
|
|
|
|
@ -2051,13 +2047,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
last_fail = ex;
|
|
|
|
|
Log.e(account.name, ex);
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " connect " + Log.formatThrowable(ex, false));
|
|
|
|
|
db.account().setAccountError(account.id, Log.formatThrowable(ex));
|
|
|
|
|
|
|
|
|
|
// Report account connection error
|
|
|
|
|
if (account.last_connected != null && !ConnectionHelper.airplaneMode(this)) {
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " last connected: " + new Date(account.last_connected));
|
|
|
|
|
|
|
|
|
|
int pollInterval = getPollInterval(this);
|
|
|
|
@ -2085,7 +2081,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
// Update state
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " closing");
|
|
|
|
|
|
|
|
|
|
// Stop watching operations
|
|
|
|
@ -2113,15 +2109,15 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
for (EntityFolder folder : mapFolders.keySet())
|
|
|
|
|
if (folder.selectable && folder.synchronize && !folder.poll && mapFolders.get(folder) != null)
|
|
|
|
|
db.folder().setFolderState(folder.id, "closing");
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " store closing");
|
|
|
|
|
iservice.close();
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " store closed");
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.w(account.name, ex);
|
|
|
|
|
} finally {
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " closed");
|
|
|
|
|
db.account().setAccountState(account.id, null);
|
|
|
|
|
for (EntityFolder folder : mapFolders.keySet())
|
|
|
|
@ -2172,7 +2168,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
" ex=" + Log.formatThrowable(last_fail, false);
|
|
|
|
|
if (compensate > 2)
|
|
|
|
|
Log.e(msg);
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT, msg);
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account, msg);
|
|
|
|
|
|
|
|
|
|
state.setBackoff(backoff * 60);
|
|
|
|
|
}
|
|
|
|
@ -2186,7 +2182,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
|
|
|
|
|
int backoff = state.getBackoff();
|
|
|
|
|
int recently = (lastLost + LOST_RECENTLY < now ? 1 : 2);
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " backoff=" + backoff + " recently=" + recently + "x");
|
|
|
|
|
|
|
|
|
|
if (backoff < CONNECT_BACKOFF_MAX)
|
|
|
|
@ -2238,7 +2234,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
|
|
|
|
try {
|
|
|
|
|
long trigger = System.currentTimeMillis() + backoff * 1000L;
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
"### " + account.name + " backoff until=" + new Date(trigger));
|
|
|
|
|
AlarmManagerCompatEx.setAndAllowWhileIdle(ServiceSynchronize.this, am, AlarmManager.RTC_WAKEUP, trigger, pi);
|
|
|
|
|
|
|
|
|
@ -2265,7 +2261,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
if (!currentThread.equals(accountThread) && accountThread != null)
|
|
|
|
|
Log.w(account.name + " orphan thread id=" + currentThread + "/" + accountThread);
|
|
|
|
|
} finally {
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " stopped");
|
|
|
|
|
wlAccount.release();
|
|
|
|
|
}
|
|
|
|
@ -2311,7 +2307,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
DB db = DB.getInstance(this);
|
|
|
|
|
|
|
|
|
|
int pollInterval = getPollInterval(this);
|
|
|
|
|
EntityLog.log(this, LOG_ACCOUNT,
|
|
|
|
|
EntityLog.log(this, EntityLog.Type.Account,
|
|
|
|
|
account.name + " auto optimize" +
|
|
|
|
|
" reason=" + reason +
|
|
|
|
|
" poll interval=" + pollInterval);
|
|
|
|
@ -2351,7 +2347,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBlockedStatusChanged(@NonNull Network network, boolean blocked) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_NETWORK,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Account,
|
|
|
|
|
"Network " + network + " blocked=" + blocked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2369,7 +2365,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
|
|
|
|
|
if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
|
|
|
|
|
boolean on = intent.getBooleanExtra("state", false);
|
|
|
|
|
EntityLog.log(context, LOG_NETWORK,
|
|
|
|
|
EntityLog.log(context, EntityLog.Type.Network,
|
|
|
|
|
"Airplane mode on=" + on);
|
|
|
|
|
if (!on)
|
|
|
|
|
lastLost = 0;
|
|
|
|
@ -2413,13 +2409,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
|
|
|
|
|
if (active != null && !active.equals(lastActive)) {
|
|
|
|
|
if (ConnectionHelper.isConnected(ServiceSynchronize.this, active)) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_NETWORK,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Network,
|
|
|
|
|
reason + ": new active network=" + active + "/" + lastActive);
|
|
|
|
|
lastActive = active;
|
|
|
|
|
}
|
|
|
|
|
} else if (lastActive != null) {
|
|
|
|
|
if (!ConnectionHelper.isConnected(ServiceSynchronize.this, lastActive)) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_NETWORK,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Network,
|
|
|
|
|
reason + ": lost active network=" + lastActive);
|
|
|
|
|
lastActive = null;
|
|
|
|
|
lastLost = new Date().getTime();
|
|
|
|
@ -2429,7 +2425,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
if (network == null || Objects.equals(network, active)) {
|
|
|
|
|
ConnectionHelper.NetworkState ns = ConnectionHelper.getNetworkState(ServiceSynchronize.this);
|
|
|
|
|
if (!Objects.equals(lastNetworkState, ns)) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_NETWORK,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Network,
|
|
|
|
|
reason + ": updating state network=" + active +
|
|
|
|
|
" info=" + ConnectionHelper.getNetworkInfo(ServiceSynchronize.this, active) + " " + ns);
|
|
|
|
|
lastNetworkState = ns;
|
|
|
|
@ -2440,7 +2436,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
boolean isSuitable = (lastNetworkState != null && lastNetworkState.isSuitable());
|
|
|
|
|
if (lastSuitable == null || lastSuitable != isSuitable) {
|
|
|
|
|
lastSuitable = isSuitable;
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_NETWORK,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Network,
|
|
|
|
|
reason + ": updated suitable=" + lastSuitable);
|
|
|
|
|
|
|
|
|
|
if (!isBackgroundService(ServiceSynchronize.this))
|
|
|
|
@ -2467,7 +2463,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
private List<TupleAccountState> lastAccountStates = null;
|
|
|
|
|
|
|
|
|
|
private void post(Bundle command) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Network,
|
|
|
|
|
"### command " + TextUtils.join(" ", Log.getExtras(command)));
|
|
|
|
|
|
|
|
|
|
if (command.getBoolean("sync") || command.getBoolean("force"))
|
|
|
|
@ -2503,7 +2499,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
networkState = ConnectionHelper.getNetworkState(ServiceSynchronize.this);
|
|
|
|
|
|
|
|
|
|
if (accountStates == null) {
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, LOG_SCHEDULE, "### no accounts");
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling, "### no accounts");
|
|
|
|
|
lastCommand = command;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -2628,7 +2624,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
|
if (polled && next < now + interval / 5)
|
|
|
|
|
next += interval;
|
|
|
|
|
|
|
|
|
|
EntityLog.log(context, LOG_SCHEDULE,
|
|
|
|
|
EntityLog.log(context, EntityLog.Type.Scheduling,
|
|
|
|
|
"Poll next=" + new Date(next) + " polled=" + polled);
|
|
|
|
|
|
|
|
|
|
AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, next, piSync);
|
|
|
|
|