Send only when suitable connection

pull/178/head
M66B 5 years ago
parent 8127267bed
commit 2691d0b6f4

@ -67,6 +67,7 @@ public class ServiceSend extends ServiceBase {
private boolean lastSuitable = false; private boolean lastSuitable = false;
private PowerManager.WakeLock wlOutbox; private PowerManager.WakeLock wlOutbox;
private TwoStateOwner owner = new TwoStateOwner("send");
private ExecutorService executor = Helper.getBackgroundExecutor(1, "send"); private ExecutorService executor = Helper.getBackgroundExecutor(1, "send");
private static final int PI_SEND = 1; private static final int PI_SEND = 1;
@ -101,7 +102,7 @@ public class ServiceSend extends ServiceBase {
}); });
// Observe send operations // Observe send operations
db.operation().liveOperations(null).observe(this, new Observer<List<TupleOperationEx>>() { db.operation().liveOperations(null).observe(owner, new Observer<List<TupleOperationEx>>() {
private List<Long> handling = new ArrayList<>(); private List<Long> handling = new ArrayList<>();
@Override @Override
@ -134,8 +135,6 @@ public class ServiceSend extends ServiceBase {
}); });
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
lastSuitable = ConnectionHelper.getNetworkState(this).isSuitable();
NetworkRequest.Builder builder = new NetworkRequest.Builder(); NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
cm.registerNetworkCallback(builder.build(), networkCallback); cm.registerNetworkCallback(builder.build(), networkCallback);
@ -245,11 +244,17 @@ public class ServiceSend extends ServiceBase {
} }
// Wait for stabilization of connection // Wait for stabilization of connection
try { if (suitable)
Thread.sleep(CONNECTIVITY_DELAY); try {
} catch (InterruptedException ex) { Thread.sleep(CONNECTIVITY_DELAY);
Log.w(ex); } catch (InterruptedException ex) {
} Log.w(ex);
}
if (suitable)
owner.start();
else
owner.stop();
} }
if (suitable) if (suitable)

Loading…
Cancel
Save