give the background worker 60 seconds to finish its work

This commit is contained in:
B. Petersen
2020-05-27 23:30:39 +02:00
parent 3bbe5ce671
commit 4423d47f44
@@ -7,6 +7,8 @@ import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import org.thoughtcrime.securesms.util.Util;
public class FetchWorker extends Worker {
private @NonNull Context context;
@@ -17,16 +19,24 @@ public class FetchWorker extends Worker {
this.context = context;
}
// doWork() is called in a background thread;
// once we return, Worker is considered to have finished and will be destroyed,
// this does not necessarily mean, that the app is killed, we may or may not keep running,
// therefore we do not stopIo() here.
@Override
public @NonNull Result doWork() {
Log.i("DeltaChat", "-------------------- FetchWorker.doWork() started --------------------");
ApplicationDcContext dcContext = DcHelper.getContext(context);
dcContext.maybeStartIo();
// as we do not know when startIo() has done it's work or if is even doable in one step,
// we go the easy way and just wait for some amount of time.
// the core has to handle interrupts at any point anyway,
// and work also maybe continued when doWork() returns.
// however, we should not wait too long here to avoid getting bad battery ratings.
Util.sleep(60 * 1000);
Log.i("DeltaChat", "-------------------- FetchWorker.doWork() done --------------------");
// TODO-ASYNC: check, that the threads get some minimal amount of time and the app is not terminated
// directly after returning
return Result.success(); // when returning, the os may terminate the app again
return Result.success();
}
}