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

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

Replace Log in SynchronizationService to use Timber

parent 91f02cd3
Loading
Loading
Loading
Loading
Loading
+23 −18
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ import android.content.SharedPreferences;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

@@ -42,12 +41,12 @@ import foundation.e.drive.operations.UploadFileOperation;
import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.DavClientProvider;
import timber.log.Timber;

/**
 * @author Vincent Bourgmayer
 */
public class SynchronizationService extends Service implements OnRemoteOperationListener {
    private final static String TAG = SynchronizationService.class.getSimpleName();
    private final SynchronizationBinder binder = new SynchronizationBinder();
    private final static int FAILURE_LIMIT = 3;
    private ConcurrentLinkedDeque<SyncRequest> syncRequestQueue;
@@ -61,9 +60,15 @@ public class SynchronizationService extends Service implements OnRemoteOperation
    private NextcloudClient ncClient;
    private Handler handler;

    @Override
    public void onCreate() {
        super.onCreate();
        Timber.tag(SynchronizationService.class.getSimpleName());
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(TAG, "onStartCommand()");
        Timber.i("onStartCommand()");

        final SharedPreferences prefs = this.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
        final String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, "");
@@ -71,7 +76,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation
        account = CommonUtils.getAccount(accountName, accountType, AccountManager.get(this));

        if (account == null) {
            Log.w(TAG, "No account available. Stop SynchronizationService");
            Timber.w("No account available");
            stopSelf();
            return START_NOT_STICKY;
        }
@@ -94,7 +99,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation

    @Override
    public void onLowMemory() {
        Log.w(TAG, "System is low on memory. Service might get killed.");
        Timber.w("System is low on memory. Service might get killed.");
    }


@@ -143,7 +148,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation
    }

    public void startSynchronization(){
        Log.d(TAG, "startAllThreads");
        Timber.i("startAllThreads");
        for(int i =-1; ++i < workerAmount;){
            this.startWorker(i);
        }
@@ -161,7 +166,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation
        if (operation != null) {
            if (CommonUtils.isThisSyncAllowed(account, request.getSyncedFileState().isMediaType())) {
                CommonUtils.createNotificationChannel(this);
                Log.v(TAG, " starts " + request.getSyncedFileState().getName()
                Timber.v(" starts " + request.getSyncedFileState().getName()
                        + " "  + request.getOperationType().name() + " on thread " + threadIndex);
                threadPool[threadIndex] = operation.execute(ocClient, this, handler);
                startedSync.put(threadIndex, syncWrapper);
@@ -187,7 +192,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation

    @Override
    public void onRemoteOperationFinish(RemoteOperation callerOperation, RemoteOperationResult result) {
        Log.d(TAG, "onRemoteOperationFinish()");
        Timber.i("onRemoteOperationFinish()");
        SyncWrapper callerWrapper = null;
        for (Map.Entry<Integer, SyncWrapper> keyValue : startedSync.entrySet()) {
            if (keyValue.getValue().getRemoteOperation().equals(callerOperation)) {
@@ -211,42 +216,42 @@ public class SynchronizationService extends Service implements OnRemoteOperation
            final String operationClassName = callerOperation.getClass().getSimpleName();
            switch (result.getCode()) {
                case OK:
                    Log.d(TAG, operationClassName + " Succeed");
                    Timber.d("%s Succeed", operationClassName);
                    break;
                case SYNC_CONFLICT:
                    //Case specific to UploadFileOperation
                    Log.e(TAG, operationClassName+" : Sync_conflict : File is already up to date");
                    Timber.e("%s : Sync_conflict : File is already up to date", operationClassName);
                    break;
                case INVALID_OVERWRITE:
                    Log.e(TAG, operationClassName + " => invalid_overwrite :\n remote file and local file doesn't have the same size");
                    Timber.e("%s => invalid_overwrite :\n remote file and local file doesn't have the same size", operationClassName);
                    break;
                case UNKNOWN_ERROR:
                    if (callerOperation instanceof UploadFileOperation) {
                        final int rowAffected = DbHelper.forceFoldertoBeRescan(((UploadFileOperation) callerOperation).getSyncedState().getId(), getApplicationContext());
                        Log.e(TAG, " Upload failed for unknown reason.\n Force folder to be rescan next time (row affected) :" + rowAffected);
                        Timber.e("Upload failed for unknown reason.\n Force folder to be rescan next time (row affected) : %s", rowAffected);
                    } else if (callerOperation instanceof DownloadFileOperation) {
                        Log.e(TAG, " Download: Unknown_error : failed");
                        Timber.e("Download: Unknown_error : failed");
                    }
                    break;
                case FORBIDDEN:
                    if (callerOperation instanceof UploadFileOperation) {
                        final int rowAffected = DbHelper.forceFoldertoBeRescan(((UploadFileOperation) callerOperation).getSyncedState().getId(), getApplicationContext());
                        Log.e(TAG, " Upload: Forbidden : Can't get syncedFileState, no remote path defined. Force folder to be rescan next time (row affected) :" + rowAffected);
                        Timber.e("Upload: Forbidden : Can't get syncedFileState, no remote path defined. Force folder to be rescan next time (row affected) : %s", rowAffected);
                    } else if (callerOperation instanceof DownloadFileOperation) {
                        Log.e(TAG, "Download : Forbidden: Can't get syncedFileState, no local path defined");
                        Timber.e("Download : Forbidden: Can't get syncedFileState, no local path defined");
                    }
                    break;
                case QUOTA_EXCEEDED:
                    //Case specific to UploadFileOperation
                    Log.w(TAG, "Quota_EXCEEDED");
                    Timber.w("Quota_EXCEEDED");
                    break;
                case FILE_NOT_FOUND:
                    //Case specific to DownloadFileOperation
                    Log.e(TAG, operationClassName+" : File_not_found: File not found after download");
                    Timber.e("%s : File_not_found: File not found after download", operationClassName);
                    break;
                case ETAG_UNCHANGED:
                    //Case specific to DownloadFileOperation
                    Log.e(TAG, operationClassName+" : Sync_conflict: File is already up to date");
                    Timber.e("%s : Sync_conflict: File is already up to date", operationClassName);
                    break;
            }
        }