From 4423d47f442e76285db55dd945a6753f51eff11f Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 27 May 2020 23:30:39 +0200 Subject: [PATCH] give the background worker 60 seconds to finish its work --- .../securesms/connect/FetchWorker.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/org/thoughtcrime/securesms/connect/FetchWorker.java b/src/org/thoughtcrime/securesms/connect/FetchWorker.java index d9eb546ec..78b4850ba 100644 --- a/src/org/thoughtcrime/securesms/connect/FetchWorker.java +++ b/src/org/thoughtcrime/securesms/connect/FetchWorker.java @@ -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(); } }