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

Commit 3724fa15 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Merge branch '304-o-removeUselessHandler' into 'v1-oreo'

Replace useless handler subclass by standard handler() in SynchronizationService

See merge request !135
parents 42a48e45 7eab788d
Loading
Loading
Loading
Loading
Loading
+2 −30
Original line number Diff line number Diff line
@@ -16,10 +16,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;

import androidx.annotation.Nullable;
@@ -29,7 +27,6 @@ import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
@@ -60,7 +57,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation
    private final int workerAmount = 4;
    private Thread[] threadPool;
    private OwnCloudClient client;
    private OperationHandler handler;
    private Handler handler;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
@@ -81,7 +78,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation
        startedSync = new ConcurrentHashMap<>();
        threadPool = new Thread[workerAmount];
        client = DavClientProvider.getInstance().getClientInstance(account, getApplicationContext());
        handler = new OperationHandler(this);
        handler = new Handler();

        return START_REDELIVER_INTENT;
    }
@@ -266,31 +263,6 @@ public class SynchronizationService extends Service implements OnRemoteOperation
        }
    }

    /**
     * Handler for the class
     */
    static class OperationHandler extends Handler {
        private final String TAG = SynchronizationService.OperationHandler.class.getSimpleName();

        private final WeakReference<SynchronizationService> serviceWeakRef;

        OperationHandler(SynchronizationService mOperationService){
            serviceWeakRef = new WeakReference<>(mOperationService);
        }

        @Override
        public void handleMessage(Message msg) {
            Log.i(TAG, "handler.handleMessage()");
            final Bundle data = msg.getData();
            if (data == null || !data.containsKey("thread index") || !data.containsKey("mThreadWorkingState")) {
                return ;
            }
            final SyncWrapper syncWrapper = serviceWeakRef.get().startedSync.get(data.getInt("thread index"));
            if (syncWrapper != null) syncWrapper.setRunning(data.getBoolean("mThreadWorkingState"));
        }
    }


    private void updateFailureCounter(SyncRequest request, boolean success) {
        final SharedPreferences prefs = getSharedPreferences(FAILED_TRANSFER_PREF, Context.MODE_PRIVATE);
        final String failure_key = request.getSyncedFileState().getLocalPath();