pull/187/head
M66B 5 years ago
parent 7261c98d60
commit e5536f79d5

@ -379,44 +379,54 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
queue.submit(new Runnable() { queue.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
Map<String, String> crumb = new HashMap<>(); try {
crumb.put("account", accountNetworkState.accountState.id.toString()); Map<String, String> crumb = new HashMap<>();
crumb.put("connected", Boolean.toString(accountNetworkState.networkState.isConnected())); crumb.put("account", accountNetworkState.accountState.id.toString());
crumb.put("suitable", Boolean.toString(accountNetworkState.networkState.isSuitable())); crumb.put("connected", Boolean.toString(accountNetworkState.networkState.isConnected()));
crumb.put("unmetered", Boolean.toString(accountNetworkState.networkState.isUnmetered())); crumb.put("suitable", Boolean.toString(accountNetworkState.networkState.isSuitable()));
crumb.put("roaming", Boolean.toString(accountNetworkState.networkState.isRoaming())); crumb.put("unmetered", Boolean.toString(accountNetworkState.networkState.isUnmetered()));
crumb.put("lastLost", new Date(lastLost).toString()); crumb.put("roaming", Boolean.toString(accountNetworkState.networkState.isRoaming()));
Log.breadcrumb("start", crumb); crumb.put("lastLost", new Date(lastLost).toString());
Log.breadcrumb("start", crumb);
Log.i("### start=" + accountNetworkState + " sync=" + sync);
astate.start(); Log.i("### start=" + accountNetworkState + " sync=" + sync);
EntityLog.log(ServiceSynchronize.this, "### started=" + accountNetworkState); astate.start();
EntityLog.log(ServiceSynchronize.this, "### started=" + accountNetworkState);
} catch (Throwable ex) {
Log.e(ex);
}
} }
}); });
} }
private void stop(final TupleAccountNetworkState accountNetworkState) { private void stop(final TupleAccountNetworkState accountNetworkState) {
EntityLog.log(ServiceSynchronize.this, "Service stop=" + accountNetworkState);
final Core.State state = coreStates.get(accountNetworkState.accountState.id); final Core.State state = coreStates.get(accountNetworkState.accountState.id);
if (state == null)
return;
coreStates.remove(accountNetworkState.accountState.id); coreStates.remove(accountNetworkState.accountState.id);
EntityLog.log(ServiceSynchronize.this, "Service stop=" + accountNetworkState);
queue.submit(new Runnable() { queue.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
Map<String, String> crumb = new HashMap<>(); try {
crumb.put("account", accountNetworkState.accountState.id.toString()); Map<String, String> crumb = new HashMap<>();
crumb.put("connected", Boolean.toString(accountNetworkState.networkState.isConnected())); crumb.put("account", accountNetworkState.accountState.id.toString());
crumb.put("suitable", Boolean.toString(accountNetworkState.networkState.isSuitable())); crumb.put("connected", Boolean.toString(accountNetworkState.networkState.isConnected()));
crumb.put("unmetered", Boolean.toString(accountNetworkState.networkState.isUnmetered())); crumb.put("suitable", Boolean.toString(accountNetworkState.networkState.isSuitable()));
crumb.put("roaming", Boolean.toString(accountNetworkState.networkState.isRoaming())); crumb.put("unmetered", Boolean.toString(accountNetworkState.networkState.isUnmetered()));
crumb.put("lastLost", new Date(lastLost).toString()); crumb.put("roaming", Boolean.toString(accountNetworkState.networkState.isRoaming()));
Log.breadcrumb("stop", crumb); crumb.put("lastLost", new Date(lastLost).toString());
Log.breadcrumb("stop", crumb);
Log.i("### stop=" + accountNetworkState);
state.stop(); Log.i("### stop=" + accountNetworkState);
state.join(); state.stop();
EntityLog.log(ServiceSynchronize.this, "### stopped=" + accountNetworkState); state.join();
EntityLog.log(ServiceSynchronize.this, "### stopped=" + accountNetworkState);
} catch (Throwable ex) {
Log.e(ex);
}
} }
}); });
} }
@ -427,12 +437,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
queue.submit(new Runnable() { queue.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
DB db = DB.getInstance(ServiceSynchronize.this); try {
db.account().deleteAccount(accountNetworkState.accountState.id); DB db = DB.getInstance(ServiceSynchronize.this);
db.account().deleteAccount(accountNetworkState.accountState.id);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.deleteNotificationChannel(EntityAccount.getNotificationChannelId(accountNetworkState.accountState.id)); nm.deleteNotificationChannel(EntityAccount.getNotificationChannelId(accountNetworkState.accountState.id));
}
} catch (Throwable ex) {
Log.e(ex);
} }
} }
}); });
@ -442,32 +456,36 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
queue.submit(new Runnable() { queue.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
EntityLog.log(ServiceSynchronize.this, "### quit eventId=" + eventId); try {
EntityLog.log(ServiceSynchronize.this, "### quit eventId=" + eventId);
if (eventId == null) { if (eventId == null) {
// Service destroy // Service destroy
DB db = DB.getInstance(ServiceSynchronize.this); DB db = DB.getInstance(ServiceSynchronize.this);
List<EntityOperation> ops = db.operation().getOperations(EntityOperation.SYNC); List<EntityOperation> ops = db.operation().getOperations(EntityOperation.SYNC);
for (EntityOperation op : ops) for (EntityOperation op : ops)
db.folder().setFolderSyncState(op.folder, null); db.folder().setFolderSyncState(op.folder, null);
} else { } else {
// Yield update notifications/widgets // Yield update notifications/widgets
try { try {
Thread.sleep(QUIT_DELAY); Thread.sleep(QUIT_DELAY);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Log.w(ex); Log.w(ex);
} }
if (!eventId.equals(lastEventId)) { if (!eventId.equals(lastEventId)) {
EntityLog.log(ServiceSynchronize.this, "### quit cancelled eventId=" + eventId + "/" + lastEventId); EntityLog.log(ServiceSynchronize.this, "### quit cancelled eventId=" + eventId + "/" + lastEventId);
return; return;
} }
// Stop service // Stop service
stopSelf(); stopSelf();
EntityLog.log(ServiceSynchronize.this, "### stop self eventId=" + eventId); EntityLog.log(ServiceSynchronize.this, "### stop self eventId=" + eventId);
WorkerCleanup.cleanupConditionally(ServiceSynchronize.this); WorkerCleanup.cleanupConditionally(ServiceSynchronize.this);
}
} catch (Throwable ex) {
Log.e(ex);
} }
} }
}); });

Loading…
Cancel
Save