From a63b237bdae269ce73ab388098a9c70c1391d60a Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 20 Jun 2021 21:05:02 +0200 Subject: [PATCH] Some tasks should not be interrupted --- app/src/main/java/eu/faircode/email/ActivitySetup.java | 4 ++-- app/src/main/java/eu/faircode/email/FragmentFolders.java | 2 +- app/src/main/java/eu/faircode/email/SimpleTask.java | 9 ++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java index 3b830ea74f..4fd842f47a 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySetup.java +++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java @@ -725,7 +725,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac ex instanceof SecurityException); Log.unexpectedError(getSupportFragmentManager(), ex, !expected); } - }.execute(this, args, "setup:export"); + }.setInterruptable(false).execute(this, args, "setup:export"); } private void handleImport(Intent data, String password) { @@ -1115,7 +1115,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac Log.unexpectedError(getSupportFragmentManager(), ex, !expected); } } - }.execute(this, args, "setup:import"); + }.setInterruptable(false).execute(this, args, "setup:import"); } private void handleImportCertificate(Intent data) { diff --git a/app/src/main/java/eu/faircode/email/FragmentFolders.java b/app/src/main/java/eu/faircode/email/FragmentFolders.java index d6d6e4ccae..5e0cef86db 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolders.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolders.java @@ -1005,7 +1005,7 @@ public class FragmentFolders extends FragmentBase { } - }.execute(this, args, "folder:export"); + }.setInterruptable(false).execute(this, args, "folder:export"); } public static class FragmentDialogApply extends FragmentDialogBase { diff --git a/app/src/main/java/eu/faircode/email/SimpleTask.java b/app/src/main/java/eu/faircode/email/SimpleTask.java index 7fb2069d73..687d377876 100644 --- a/app/src/main/java/eu/faircode/email/SimpleTask.java +++ b/app/src/main/java/eu/faircode/email/SimpleTask.java @@ -51,6 +51,7 @@ import java.util.concurrent.Future; public abstract class SimpleTask implements LifecycleObserver { private boolean log = true; private boolean count = true; + private boolean interruptable = true; private String name; private long started; @@ -82,6 +83,11 @@ public abstract class SimpleTask implements LifecycleObserver { return this; } + public SimpleTask setInterruptable(boolean interruptable) { + this.interruptable = interruptable; + return this; + } + public SimpleTask setExecutor(ExecutorService executor) { this.localExecutor = executor; return this; @@ -284,7 +290,8 @@ public abstract class SimpleTask implements LifecycleObserver { long elapsed = now - task.started; if (elapsed > CANCEL_AFTER && !task.interrupted) { task.interrupted = true; - if (task.future != null && !task.future.isDone()) { + if (task.interruptable && + task.future != null && !task.future.isDone()) { Log.e("Interrupting task " + task + " tasks=" + getCountLocked() + "/" + tasks.size()); task.future.cancel(true);