mirror of https://github.com/M66B/FairEmail.git
Switch to handler thread to execute operations
This commit is contained in:
parent
83e62fcfca
commit
178ad45159
|
@ -35,6 +35,8 @@ import android.net.NetworkInfo;
|
||||||
import android.net.NetworkRequest;
|
import android.net.NetworkRequest;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerThread;
|
||||||
import android.os.OperationCanceledException;
|
import android.os.OperationCanceledException;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
|
@ -881,8 +883,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
wlAccount.acquire();
|
wlAccount.acquire();
|
||||||
|
|
||||||
final DB db = DB.getInstance(this);
|
final DB db = DB.getInstance(this);
|
||||||
final ExecutorService executor =
|
|
||||||
Helper.getBackgroundExecutor(1, "account_" + account.id);
|
|
||||||
|
|
||||||
long thread = Thread.currentThread().getId();
|
long thread = Thread.currentThread().getId();
|
||||||
Long currentThread = thread;
|
Long currentThread = thread;
|
||||||
|
@ -914,6 +914,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
|
|
||||||
final List<TwoStateOwner> cowners = new ArrayList<>();
|
final List<TwoStateOwner> cowners = new ArrayList<>();
|
||||||
|
|
||||||
|
HandlerThread ht = new HandlerThread("account_" + account.id, THREAD_PRIORITY_BACKGROUND);
|
||||||
|
ht.start();
|
||||||
|
final Handler handler = new Handler(ht.getLooper());
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
boolean debug = (prefs.getBoolean("debug", false) || BuildConfig.DEBUG);
|
boolean debug = (prefs.getBoolean("debug", false) || BuildConfig.DEBUG);
|
||||||
|
@ -1294,7 +1298,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
|
|
||||||
final long sequence = state.getSequence(folder.id, key.getPriority());
|
final long sequence = state.getSequence(folder.id, key.getPriority());
|
||||||
|
|
||||||
executor.submit(new Helper.PriorityRunnable(key.getPriority(), key.getOrder()) {
|
handler.post(new Helper.PriorityRunnable(key.getPriority(), key.getOrder()) {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
super.run();
|
super.run();
|
||||||
|
@ -1610,6 +1614,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
|
|
||||||
// Cancel running operations
|
// Cancel running operations
|
||||||
state.resetBatches();
|
state.resetBatches();
|
||||||
|
ht.quit();
|
||||||
|
|
||||||
// Close folders
|
// Close folders
|
||||||
for (EntityFolder folder : mapFolders.keySet())
|
for (EntityFolder folder : mapFolders.keySet())
|
||||||
|
|
Loading…
Reference in New Issue