|
|
@ -21,6 +21,7 @@ package eu.faircode.email;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Handler;
|
|
|
|
|
|
|
|
|
|
|
@ -33,6 +34,7 @@ import androidx.lifecycle.LifecycleOwner;
|
|
|
|
import androidx.lifecycle.LifecycleService;
|
|
|
|
import androidx.lifecycle.LifecycleService;
|
|
|
|
import androidx.lifecycle.OnLifecycleEvent;
|
|
|
|
import androidx.lifecycle.OnLifecycleEvent;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
@ -54,11 +56,9 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|
|
|
private String name;
|
|
|
|
private String name;
|
|
|
|
private Future<?> future;
|
|
|
|
private Future<?> future;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static ExecutorService executor = null;
|
|
|
|
private static final List<SimpleTask> tasks = new ArrayList<>();
|
|
|
|
private static final List<SimpleTask> tasks = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
private static final ExecutorService executor =
|
|
|
|
|
|
|
|
Helper.getBackgroundExecutor(Runtime.getRuntime().availableProcessors(), "task");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final String ACTION_TASK_COUNT = BuildConfig.APPLICATION_ID + ".ACTION_TASK_COUNT";
|
|
|
|
static final String ACTION_TASK_COUNT = BuildConfig.APPLICATION_ID + ".ACTION_TASK_COUNT";
|
|
|
|
|
|
|
|
|
|
|
|
public SimpleTask<T> setLog(boolean log) {
|
|
|
|
public SimpleTask<T> setLog(boolean log) {
|
|
|
@ -117,6 +117,13 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|
|
|
onException(args, ex);
|
|
|
|
onException(args, ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (executor == null) {
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
|
|
|
|
int threads = prefs.getInt("query_threads", Runtime.getRuntime().availableProcessors());
|
|
|
|
|
|
|
|
Log.i("Task threads=" + threads);
|
|
|
|
|
|
|
|
executor = Helper.getBackgroundExecutor(threads, "task");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
future = executor.submit(new Runnable() {
|
|
|
|
future = executor.submit(new Runnable() {
|
|
|
|
private Object data;
|
|
|
|
private Object data;
|
|
|
|
private long elapse;
|
|
|
|
private long elapse;
|
|
|
|