Restored send delay

pull/184/head
M66B 4 years ago
parent 16e6d46631
commit ae0c2478cf

@ -79,6 +79,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
private static final int PI_SEND = 1; private static final int PI_SEND = 1;
private static final int RETRY_MAX = 3; private static final int RETRY_MAX = 3;
private static final int CONNECTIVITY_DELAY = 5000; // milliseconds
@Override @Override
public void onCreate() { public void onCreate() {
@ -289,39 +290,46 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
} }
private void _checkConnectivity() { private void _checkConnectivity() {
Network active = ConnectionHelper.getActiveNetwork(this); final Network active = ConnectionHelper.getActiveNetwork(this);
boolean restart = !Objects.equals(lastActive, active); final boolean restart = !Objects.equals(lastActive, active);
if (restart) { final boolean suitable = ConnectionHelper.getNetworkState(this).isSuitable();
lastActive = active;
EntityLog.log(this, "Service send active=" + active);
if (lastSuitable) {
EntityLog.log(this, "Service send restart");
lastSuitable = false;
owner.stop();
handling.clear();
}
}
boolean suitable = ConnectionHelper.getNetworkState(this).isSuitable(); if (restart || lastSuitable != suitable)
if (lastSuitable != suitable) { new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
lastSuitable = suitable; @Override
EntityLog.log(this, "Service send suitable=" + suitable); public void run() {
if (restart) {
lastActive = active;
EntityLog.log(ServiceSend.this, "Service send active=" + active);
if (lastSuitable) {
EntityLog.log(ServiceSend.this, "Service send restart");
lastSuitable = false;
owner.stop();
handling.clear();
}
}
try { if (lastSuitable != suitable) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); lastSuitable = suitable;
nm.notify(Helper.NOTIFICATION_SEND, getNotificationService().build()); EntityLog.log(ServiceSend.this, "Service send suitable=" + suitable);
} catch (Throwable ex) {
Log.w(ex);
}
if (suitable) try {
owner.start(); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
else { nm.notify(Helper.NOTIFICATION_SEND, getNotificationService().build());
owner.stop(); } catch (Throwable ex) {
handling.clear(); Log.w(ex);
} }
}
if (suitable)
owner.start();
else {
owner.stop();
handling.clear();
}
}
}
}, CONNECTIVITY_DELAY);
} }
private void processOperations(List<TupleOperationEx> ops) { private void processOperations(List<TupleOperationEx> ops) {

Loading…
Cancel
Save