Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cdb9de2a authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Merge branch '723-o-try-threadHandler' into 'v1-oreo'

Execute RemoteOperation on ThreadHandler instead of main thread:

See merge request !171
parents 97371a6a 9e303fe0
Loading
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;

import androidx.annotation.Nullable;
@@ -72,12 +73,15 @@ public class ObserverService extends Service implements OnRemoteOperationListene
    private Account mAccount;
    private HashMap<Integer, SyncRequest> syncRequests; //integer is SyncedFileState id; Parcelable is the operation
    private SynchronizationServiceConnection synchronizationServiceConnection = new SynchronizationServiceConnection();
    private Handler handler;
    private HandlerThread handlerThread;

    /* Lifecycle Methods */
    @Override
    public void onDestroy(){
        Timber.v("onDestroy()");
        unbindService(synchronizationServiceConnection);
        handlerThread.quitSafely();
        super.onDestroy();
        this.mSyncedFolders = null;
    }
@@ -110,6 +114,10 @@ public class ObserverService extends Service implements OnRemoteOperationListene

        this.syncRequests = new HashMap<>();
        initialFolderCounter = prefs.getInt(AppConstants.INITIALFOLDERS_NUMBER, 0);

        handlerThread = new HandlerThread("syncService_onResponse");
        handlerThread.start();
        handler = new Handler(handlerThread.getLooper());
        begin();
        return START_NOT_STICKY;
    }
@@ -256,7 +264,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene

            try {
                final ListFileRemoteOperation loadOperation = new ListFileRemoteOperation(this.mSyncedFolders, this, this.initialFolderCounter);
                loadOperation.execute(client, this, new Handler());
                loadOperation.execute(client, this, handler);
            } catch (IllegalArgumentException exception) {
                Timber.e(exception);
            }
+12 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Binder;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;

import androidx.annotation.Nullable;
@@ -60,7 +61,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation
    private OwnCloudClient ocClient;
    private NextcloudClient ncClient;
    private Handler handler;

    private HandlerThread handlerThread;
    @Override
    public void onCreate() {
        super.onCreate();
@@ -87,11 +88,20 @@ public class SynchronizationService extends Service implements OnRemoteOperation
        threadPool = new Thread[workerAmount];
        ocClient = DavClientProvider.getInstance().getClientInstance(account, getApplicationContext());
        ncClient = DavClientProvider.getInstance().getNcClientInstance(account, getApplicationContext());
        handler = new Handler();

        handlerThread = new HandlerThread("syncService_onResponse");
        handlerThread.start();
        handler = new Handler(handlerThread.getLooper());

        return START_REDELIVER_INTENT;
    }

    @Override
    public void onDestroy() {
        handlerThread.quitSafely();
        super.onDestroy();
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {