|
|
|
@ -138,8 +138,27 @@ public class ServiceSend extends LifecycleService {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAvailable(Network network) {
|
|
|
|
|
Log.i("Service send available=" + network);
|
|
|
|
|
if (isConnected())
|
|
|
|
|
run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCapabilitiesChanged(Network network, NetworkCapabilities caps) {
|
|
|
|
|
Log.i("Service send caps=" + caps);
|
|
|
|
|
if (isConnected())
|
|
|
|
|
run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isConnected() {
|
|
|
|
|
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
|
NetworkInfo ni = cm.getActiveNetworkInfo();
|
|
|
|
|
return (ni != null && ni.isConnected());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void run() {
|
|
|
|
|
if (thread != null && thread.isAlive())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (thread == null || !thread.isAlive()) {
|
|
|
|
|
thread = new Thread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
@ -155,8 +174,6 @@ public class ServiceSend extends LifecycleService {
|
|
|
|
|
db.folder().setFolderError(outbox.id, null);
|
|
|
|
|
db.folder().setFolderSyncState(outbox.id, "syncing");
|
|
|
|
|
|
|
|
|
|
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
|
|
|
|
|
|
List<EntityOperation> ops = db.operation().getOperations(outbox.id);
|
|
|
|
|
Log.i(outbox.name + " pending operations=" + ops.size());
|
|
|
|
|
for (EntityOperation op : ops) {
|
|
|
|
@ -200,8 +217,7 @@ public class ServiceSend extends LifecycleService {
|
|
|
|
|
Log.i(outbox.name + " end op=" + op.id + "/" + op.name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetworkInfo ni = cm.getActiveNetworkInfo();
|
|
|
|
|
if (ni == null || !ni.isConnected())
|
|
|
|
|
if (!isConnected())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -221,7 +237,6 @@ public class ServiceSend extends LifecycleService {
|
|
|
|
|
});
|
|
|
|
|
thread.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private void send(EntityMessage message) throws MessagingException, IOException {
|
|
|
|
|