From 359a6d5059221d11830dc738477120f008bddf10 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 31 May 2023 17:34:41 +0200 Subject: [PATCH 01/11] Replace locale file deletion task, by file sync disabling task. --- .../java/foundation/e/drive/RecycleBin.kt | 86 ------------------- .../contentScanner/RemoteContentScanner.java | 6 +- .../e/drive/models/SyncRequest.java | 2 +- .../e/drive/models/SyncedFileState.java | 7 ++ .../services/SynchronizationService.java | 14 +-- .../foundation/e/drive/utils/CommonUtils.java | 1 - .../e/drive/work/FileSyncDisabler.java | 55 ++++++++++++ .../e/drive/work/FirstStartWorker.java | 5 -- .../e/drive/work/LocalFileDeleter.java | 64 -------------- .../e/drive/work/RecycleBinCleaningWorker.kt | 34 -------- .../e/drive/work/WorkRequestFactory.java | 13 --- .../RemoteContentScannerTest.java | 2 +- 12 files changed, 74 insertions(+), 215 deletions(-) delete mode 100644 app/src/main/java/foundation/e/drive/RecycleBin.kt create mode 100644 app/src/main/java/foundation/e/drive/work/FileSyncDisabler.java delete mode 100644 app/src/main/java/foundation/e/drive/work/LocalFileDeleter.java delete mode 100644 app/src/main/java/foundation/e/drive/work/RecycleBinCleaningWorker.kt diff --git a/app/src/main/java/foundation/e/drive/RecycleBin.kt b/app/src/main/java/foundation/e/drive/RecycleBin.kt deleted file mode 100644 index 447106bb..00000000 --- a/app/src/main/java/foundation/e/drive/RecycleBin.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright © MURENA SAS 2023. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html - */ - -@file:JvmName("RecycleBin") - -package foundation.e.drive - -import foundation.e.drive.utils.AppConstants -import timber.log.Timber -import java.io.File -import java.io.IOException -import java.nio.file.Files -import kotlin.io.path.Path -import kotlin.time.Duration -import kotlin.time.DurationUnit -import kotlin.time.toDuration - -/** - * This class contains method for trashing file & cleaning the trash - */ -object RecycleBin { - private val DELAY_FOR_DELETION = 30.toDuration(DurationUnit.DAYS) - private val BIN_PATH = AppConstants.RECYCLE_BIN_PATH //TMP only, Need to find a way to get context - - /** - * Remove files which are in recycle bin - * for more than DELAY_FOR_DELETION - * @return false as soon as some files that should be removed is not removed - */ - fun clearOldestFiles(): Boolean { - val binDir = File(BIN_PATH) - - if (!binDir.exists()) return true - - try { - val filesToRemove = binDir.listFiles { file -> - computeTimeInBin(file.lastModified()) > DELAY_FOR_DELETION - } - - filesToRemove?.forEach { file -> file?.delete() } - } catch (exception: IOException) { - //Note that some files might have already been removed - Timber.e(exception, "Caught exception when clearing oldest file in bin") - return false - } - return true - } - - /** - * Compute time from which file is in Bin - * and return it as a Duration in days - */ - private fun computeTimeInBin(fileLastModified: Long): Duration { - return (System.currentTimeMillis() - fileLastModified).toDuration(DurationUnit.DAYS) - } - - /** - * put a file into the bin - */ - fun trashFile(file: File): Boolean { - File(BIN_PATH).mkdirs() //Assert that recycle bin exist - - if (file.exists()) { - val targetPath = File(BIN_PATH, file.name).absolutePath - try { - val moveResult = Files.move(file.toPath(), Path(targetPath)) - if (moveResult.toFile().exists()) { - return true - } - } catch (exception: IOException) { - Timber.e(exception) - } catch (exception: SecurityException) { - Timber.e(exception) - } catch (exception: NullPointerException) { - Timber.e(exception) - } - } - Timber.d("Can't move %s to trashbin", file.absolutePath) - return false - } -} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java b/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java index 37b1ffc5..5748abe4 100644 --- a/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java +++ b/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java @@ -7,7 +7,7 @@ */ package foundation.e.drive.contentScanner; -import static foundation.e.drive.models.SyncRequest.Type.LOCAL_DELETE; +import static foundation.e.drive.models.SyncRequest.Type.DISABLE_SYNCING; import static foundation.e.drive.utils.FileDiffUtils.getActionForFileDiff; import android.content.Context; @@ -88,8 +88,8 @@ public class RemoteContentScanner extends AbstractContentScanner { return; } - Timber.d("Add local deletion request for file: %s", fileState.getLocalPath()); - this.syncRequests.put(fileState.getId(), new SyncRequest(fileState, LOCAL_DELETE)); + Timber.d("Add Disable syncing request for file: %s", fileState.getLocalPath()); + this.syncRequests.put(fileState.getId(), new SyncRequest(fileState, DISABLE_SYNCING)); } @Override diff --git a/app/src/main/java/foundation/e/drive/models/SyncRequest.java b/app/src/main/java/foundation/e/drive/models/SyncRequest.java index 239217d1..73f46562 100644 --- a/app/src/main/java/foundation/e/drive/models/SyncRequest.java +++ b/app/src/main/java/foundation/e/drive/models/SyncRequest.java @@ -11,7 +11,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; public class SyncRequest { - public enum Type { UPLOAD, DOWNLOAD, REMOTE_DELETE, LOCAL_DELETE}; + public enum Type { UPLOAD, DOWNLOAD, REMOTE_DELETE, DISABLE_SYNCING}; private final SyncedFileState syncedFileState; diff --git a/app/src/main/java/foundation/e/drive/models/SyncedFileState.java b/app/src/main/java/foundation/e/drive/models/SyncedFileState.java index 0c07ddc9..927545f6 100644 --- a/app/src/main/java/foundation/e/drive/models/SyncedFileState.java +++ b/app/src/main/java/foundation/e/drive/models/SyncedFileState.java @@ -211,4 +211,11 @@ public class SyncedFileState implements Parcelable { public int describeContents() { return 0; } + + /** + * Disable syncing of the concerned file + */ + public void setUnsyncable() { + this.scannable = NOT_SCANNABLE; + } } diff --git a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java index 92df659f..0cf78b77 100644 --- a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java +++ b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java @@ -44,13 +44,13 @@ 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 foundation.e.drive.work.LocalFileDeleter; +import foundation.e.drive.work.FileSyncDisabler; import timber.log.Timber; /** * @author Vincent Bourgmayer */ -public class SynchronizationService extends Service implements OnRemoteOperationListener, LocalFileDeleter.LocalFileDeletionListener { +public class SynchronizationService extends Service implements OnRemoteOperationListener, FileSyncDisabler.FileSyncDisablingListener { private final SynchronizationBinder binder = new SynchronizationBinder(); private final static long maxPauseTimeInMs = 300000; //5 minutes, might need to be adapted private ConcurrentLinkedDeque syncRequestQueue; @@ -244,12 +244,12 @@ public class SynchronizationService extends Service implements OnRemoteOperation final SyncWrapper syncWrapper = new SyncWrapper(request, account, getApplicationContext()); - if (request.getOperationType().equals(SyncRequest.Type.LOCAL_DELETE)) { + if (request.getOperationType().equals(SyncRequest.Type.DISABLE_SYNCING)) { Timber.v(" starts " + request.getSyncedFileState().getName() + " local deletion on thread " + threadIndex); - final LocalFileDeleter fileDeleter = new LocalFileDeleter(request.getSyncedFileState()); - threadPool[threadIndex] = new Thread(fileDeleter.getRunnable( handler, threadIndex, getApplicationContext(), this)); + final FileSyncDisabler fileSyncDisabler = new FileSyncDisabler(request.getSyncedFileState()); + threadPool[threadIndex] = new Thread(fileSyncDisabler.getRunnable( handler, threadIndex, getApplicationContext(), this)); threadPool[threadIndex].start(); startedSync.put(threadIndex, syncWrapper); return; @@ -381,10 +381,10 @@ public class SynchronizationService extends Service implements OnRemoteOperation } @Override - public void onDeletionComplete(int threadId, boolean succeed) { + public void onSyncDisabled(int threadId, boolean succeed) { final SyncWrapper wrapper = startedSync.get(threadId); if (wrapper != null) { - Timber.d(wrapper.getRequest().getSyncedFileState().getLocalPath() + " deletion result: " + succeed); + Timber.d(wrapper.getRequest().getSyncedFileState().getLocalPath() + " sync disabled? " + succeed); wrapper.setRunning(false); } startWorker(threadId); diff --git a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java index 86e67971..1ffb3a1e 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -24,7 +24,6 @@ import android.net.ConnectivityManager; import android.net.NetworkCapabilities; import android.net.Uri; -import android.os.Build; import android.webkit.MimeTypeMap; import android.widget.Toast; diff --git a/app/src/main/java/foundation/e/drive/work/FileSyncDisabler.java b/app/src/main/java/foundation/e/drive/work/FileSyncDisabler.java new file mode 100644 index 00000000..7b883737 --- /dev/null +++ b/app/src/main/java/foundation/e/drive/work/FileSyncDisabler.java @@ -0,0 +1,55 @@ +/* + * Copyright © MURENA SAS 2022. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + */ +package foundation.e.drive.work; + +import android.content.Context; +import android.os.Handler; + +import androidx.annotation.NonNull; + +import foundation.e.drive.database.DbHelper; +import foundation.e.drive.models.SyncedFileState; +import timber.log.Timber; + +/** + * New Goal: Disable eDrive Synchronization of the given file + * + * previous goal: This worker is called when a remote file has been detected as removed and that all the + * scanning process lead to choose to delete the local version too. + * + * @author vincent Bourgmayer + */ +public class FileSyncDisabler { + + public interface FileSyncDisablingListener { + void onSyncDisabled(int threadId, boolean succeed); + } + + private final SyncedFileState fileState; + + public FileSyncDisabler(@NonNull SyncedFileState syncedFileState) { + fileState = syncedFileState; + } + + @NonNull + public Runnable getRunnable(@NonNull final Handler handler, final int threadId, @NonNull final Context context, @NonNull final FileSyncDisablingListener listener) { + return () -> { + + fileState.setUnsyncable(); + if (DbHelper.manageSyncedFileStateDB(fileState, "UPDATE", context) <= 0) { + Timber.d("Failed to remove %s from DB", fileState.getName()); + } + + notifyCompletion(threadId, listener, true, handler); + }; + } + + private void notifyCompletion(final int threadId, final @NonNull FileSyncDisablingListener listener, final boolean success, @NonNull final Handler handler) { + handler.post(() -> listener.onSyncDisabled(threadId, success)); + } +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java index 5890e103..7cdbf4f1 100644 --- a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java @@ -10,7 +10,6 @@ package foundation.e.drive.work; import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import static foundation.e.drive.work.WorkRequestFactory.WorkType.ONE_TIME_APP_LIST; -import static foundation.e.drive.work.WorkRequestFactory.WorkType.PERIODIC_CLEANING; import static foundation.e.drive.work.WorkRequestFactory.WorkType.PERIODIC_SCAN; import android.content.Context; @@ -75,9 +74,5 @@ public class FirstStartWorker extends Worker { workManager.enqueueUniquePeriodicWork(PeriodicWorker.UNIQUE_WORK_NAME, ExistingPeriodicWorkPolicy.KEEP, WorkRequestFactory.getPeriodicWorkRequest(PERIODIC_SCAN)); - - workManager.enqueueUniquePeriodicWork(RecycleBinCleaningWorker.UNIQUE_NAME, - ExistingPeriodicWorkPolicy.KEEP, - WorkRequestFactory.getPeriodicWorkRequest(PERIODIC_CLEANING)); } } \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/work/LocalFileDeleter.java b/app/src/main/java/foundation/e/drive/work/LocalFileDeleter.java deleted file mode 100644 index ad6b36d8..00000000 --- a/app/src/main/java/foundation/e/drive/work/LocalFileDeleter.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright © MURENA SAS 2022. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html - */ -package foundation.e.drive.work; - -import android.content.Context; -import android.os.Handler; -import android.provider.MediaStore; - -import androidx.annotation.NonNull; - -import java.io.File; - -import foundation.e.drive.RecycleBin; -import foundation.e.drive.database.DbHelper; -import foundation.e.drive.models.SyncedFileState; -import foundation.e.drive.utils.CommonUtils; -import timber.log.Timber; - -/** - * This worker is called when a remote file has been detected as removed and that all the - * scanning process lead to choose to delete the local version too. - * @author vincent Bourgmayer - */ -public class LocalFileDeleter { - - public interface LocalFileDeletionListener { - void onDeletionComplete(int threadId, boolean succeed); - } - - private final SyncedFileState fileState; - - public LocalFileDeleter(@NonNull SyncedFileState syncedFileState) { - fileState = syncedFileState; - } - - @NonNull - public Runnable getRunnable(@NonNull final Handler handler, final int threadId, @NonNull final Context context, @NonNull final LocalFileDeletionListener listener) { - return () -> { - final File file = new File(fileState.getLocalPath()); - final boolean succeed = RecycleBin.INSTANCE.trashFile(file); - - if (succeed) { - context.getContentResolver().delete(MediaStore.Files.getContentUri("external"), - MediaStore.Files.FileColumns.DATA + "=?", - new String[]{CommonUtils.getLocalPath(file)}); - - if (DbHelper.manageSyncedFileStateDB(fileState, "DELETE", context) <= 0) { - Timber.d("Failed to remove %s from DB", file.getName()); - } - } - - notifyCompletion(threadId, listener, succeed, handler); - }; - } - - private void notifyCompletion(final int threadId, final @NonNull LocalFileDeletionListener listener, final boolean success, @NonNull final Handler handler) { - handler.post(() -> listener.onDeletionComplete(threadId, success)); - } -} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/work/RecycleBinCleaningWorker.kt b/app/src/main/java/foundation/e/drive/work/RecycleBinCleaningWorker.kt deleted file mode 100644 index 45328ed3..00000000 --- a/app/src/main/java/foundation/e/drive/work/RecycleBinCleaningWorker.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © MURENA SAS 2023. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html - */ -package foundation.e.drive.work - -import android.content.Context -import androidx.work.Worker -import androidx.work.WorkerParameters -import foundation.e.drive.RecycleBin - -/** - * This class is the worker that call cleaning of eDrive's technical files - * and cleaning - * @author Vincent Bourgmayer - */ - -class RecycleBinCleaningWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { - companion object { - const val UNIQUE_NAME = "binCleaner" - } - - override fun doWork(): Result { - val result = RecycleBin.clearOldestFiles() - - if (result) - return Result.success() - else - return Result.failure() - } -} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java index 1e16cab4..6331f302 100644 --- a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java +++ b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java @@ -38,7 +38,6 @@ public class WorkRequestFactory { public enum WorkType { PERIODIC_USER_INFO, PERIODIC_SCAN, - PERIODIC_CLEANING, ONE_TIME_FULL_SCAN, ONE_TIME_APP_LIST, ONE_TIME_USER_INFO, @@ -59,23 +58,11 @@ public class WorkRequestFactory { return createPeriodicScanWorkRequest(); case PERIODIC_USER_INFO: return createPeriodicGetUserInfoWorkRequest(); - case PERIODIC_CLEANING: - return createPeriodicCleaningWorkRequest(); default: throw new InvalidParameterException("Unsupported Work Type: " + type); } } - /** - * Create a periodic work request that clean the trash bin - * @return - */ - private static PeriodicWorkRequest createPeriodicCleaningWorkRequest() { - return new PeriodicWorkRequest.Builder(RecycleBinCleaningWorker.class, 1, TimeUnit.DAYS, 2, TimeUnit.HOURS) - .addTag(AppConstants.WORK_GENERIC_TAG) - .build(); - } - /** * Create a PeridocWorkRequest instance for * a Full scan with constraints on network (should diff --git a/app/src/test/java/foundation/e/drive/contentScanner/RemoteContentScannerTest.java b/app/src/test/java/foundation/e/drive/contentScanner/RemoteContentScannerTest.java index ae291d14..9375919c 100644 --- a/app/src/test/java/foundation/e/drive/contentScanner/RemoteContentScannerTest.java +++ b/app/src/test/java/foundation/e/drive/contentScanner/RemoteContentScannerTest.java @@ -96,7 +96,7 @@ public class RemoteContentScannerTest { Assert.assertEquals("scanResult's size doesn't match the expected result", 3, scanResult.size()); for (SyncRequest request : scanResult.values()) { - Assert.assertEquals("SyncRequest's type should be LOCAL_DELETE but is "+request.getOperationType(), SyncRequest.Type.LOCAL_DELETE, request.getOperationType()); + Assert.assertEquals("SyncRequest's type should be LOCAL_DELETE but is "+request.getOperationType(), SyncRequest.Type.DISABLE_SYNCING, request.getOperationType()); } } -- GitLab From badb12e38f155b0f4a53964f379e81498e2cdda2 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 1 Jun 2023 14:46:44 +0200 Subject: [PATCH 02/11] add rule to linter to ignore duplicate Strings. due to issue with values-is dir --- lint.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lint.xml b/lint.xml index 8f925319..64b52e02 100644 --- a/lint.xml +++ b/lint.xml @@ -5,7 +5,8 @@ - + + -- GitLab From f1ed9dcda4015679bb93036d1ad501be95271f77 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 1 Jun 2023 17:47:12 +0200 Subject: [PATCH 03/11] disable code that restore scannable value for media files --- .../foundation/e/drive/database/DbHelper.java | 20 +------------------ .../e/drive/database/SyncedFileStateDAO.java | 14 ------------- 2 files changed, 1 insertion(+), 33 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/database/DbHelper.java b/app/src/main/java/foundation/e/drive/database/DbHelper.java index ae0b3033..a71ca586 100644 --- a/app/src/main/java/foundation/e/drive/database/DbHelper.java +++ b/app/src/main/java/foundation/e/drive/database/DbHelper.java @@ -165,7 +165,7 @@ public final class DbHelper extends SQLiteOpenHelper { * @return empty list if DB opening failed, either return the list of SyncedFileState */ @NonNull - public static List getSyncedFileStatesByFolders(@NonNull Context context, @NonNull List ids) {//Connect to DB + public static List getSyncedFileStatesByFolders(@NonNull Context context, @NonNull List ids) { final SyncedFileStateDAO dao = openSyncedFileStateDAO(context, false); if (dao == null) { return new ArrayList<>(); @@ -182,7 +182,6 @@ public final class DbHelper extends SQLiteOpenHelper { * @return number of affected row. Return -1 if failed */ public static int updateSyncedFolders(@NonNull List syncedFolders, @NonNull Context context){ - int result = -1; final SyncedFolderDAO dao = openSyncedFolderDAO(context, true); @@ -259,22 +258,6 @@ public final class DbHelper extends SQLiteOpenHelper { return id; } - /** - * Delete a syncedFolder in DB - * @param id Id of the syncedFOlder to persist - * @param context Context of the app - * @return int number of row affected - */ - public static int deleteSyncedFolder(long id, @NonNull Context context){ - final SyncedFolderDAO dao = openSyncedFolderDAO(context, true); - if (dao == null) { - return -1; - } - final int result = dao.delete(id); - dao.close(); - return result; - } - @Nullable public static SyncedFolder getSyncedFolderByLocalPath(@NonNull String localPath, @NonNull Context context){ final SyncedFolderDAO dao = openSyncedFolderDAO(context, true); @@ -374,7 +357,6 @@ public final class DbHelper extends SQLiteOpenHelper { public static void cleanSyncedFileStateTableAfterUpdate(@NonNull Context context) throws SQLiteException { final SyncedFileStateDAO dao = openSyncedFileStateDAO(context, true); dao.deleteHiddenFileStates(); - dao.updateUnscannableMediaFiles(); dao.close(); } } diff --git a/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java b/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java index 9716201f..9af36d51 100644 --- a/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java +++ b/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java @@ -122,20 +122,6 @@ import timber.log.Timber; return mDB.delete(TABLE_NAME, FILE_NAME + " LIKE ?", new String[]{".%"}); } - /** - * In previous version, when a synchronized file was removed, the DB value for scannable column - * was set to "0"; Now we consider those entries has to be scannable set to "2" in order to let synchronization algo - * to remove them - * @return number of deleted input - */ - /* package */ int updateUnscannableMediaFiles() { - final ContentValues value = new ContentValues(); - value.put(SCANNABLE, SyncedFileState.DEVICE_SCANNABLE); - final String whereClause = IS_MEDIA_TYPE + " =1 AND " + SCANNABLE + " ="+SyncedFileState.NOT_SCANNABLE; - - return mDB.update(TABLE_NAME, value, whereClause, null); - } - /** * Update a specific syncedFile * @param syncedFileState SyncedFileState to update -- GitLab From 459cc0530fe1265645faae37ecc0e6f3da3a062c Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 1 Jun 2023 18:08:12 +0200 Subject: [PATCH 04/11] Ignore unscannable file in *contentScanner.java --- .../e/drive/contentScanner/AbstractContentScanner.java | 5 ++++- .../e/drive/contentScanner/LocalContentScanner.java | 2 ++ .../e/drive/contentScanner/RemoteContentScanner.java | 2 ++ .../foundation/e/drive/contentScanner/RemoteFileLister.java | 3 +-- .../java/foundation/e/drive/models/SyncedFileState.java | 6 ++---- .../java/foundation/e/drive/services/ObserverService.java | 2 +- .../main/java/foundation/e/drive/utils/FileDiffUtils.java | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/contentScanner/AbstractContentScanner.java b/app/src/main/java/foundation/e/drive/contentScanner/AbstractContentScanner.java index f2cce745..bdf4606b 100644 --- a/app/src/main/java/foundation/e/drive/contentScanner/AbstractContentScanner.java +++ b/app/src/main/java/foundation/e/drive/contentScanner/AbstractContentScanner.java @@ -68,6 +68,9 @@ public abstract class AbstractContentScanner { } for (SyncedFileState remainingFileState : fileStates) { + if (remainingFileState.getScannable() == SyncedFileState.NOT_SCANNABLE) { + continue; + } onMissingFile(remainingFileState); } return syncRequests; @@ -114,4 +117,4 @@ public abstract class AbstractContentScanner { protected abstract void onKnownFileFound(@NonNull T file, @NonNull SyncedFileState fileState); protected abstract boolean isFileMatchingSyncedFileState(@NonNull T file, @NonNull SyncedFileState fileState); protected abstract boolean isSyncedFolderParentOfFile(@NonNull SyncedFolder syncedFolder, @NonNull String dirPath); -} +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java b/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java index dbc5864c..99d8735a 100644 --- a/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java +++ b/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java @@ -73,6 +73,8 @@ public class LocalContentScanner extends AbstractContentScanner{ @Override protected void onKnownFileFound(@NonNull File file, @NonNull SyncedFileState fileState) { + if (fileState.getScannable() == SyncedFileState.NOT_SCANNABLE) return; + if (FileDiffUtils.getActionForFileDiff(file, fileState) == FileDiffUtils.Action.Upload) { Timber.d("Add upload SyncRequest for %s", file.getAbsolutePath()); syncRequests.put(fileState.getId(), new SyncRequest(fileState, SyncRequest.Type.UPLOAD)); diff --git a/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java b/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java index 5748abe4..f64c010f 100644 --- a/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java +++ b/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java @@ -43,6 +43,8 @@ public class RemoteContentScanner extends AbstractContentScanner { @Override protected void onKnownFileFound(@NonNull RemoteFile file, @NonNull SyncedFileState fileState) { + if (fileState.getScannable() == SyncedFileState.NOT_SCANNABLE) return; + final FileDiffUtils.Action action = getActionForFileDiff(file, fileState); if (action == FileDiffUtils.Action.Download) { diff --git a/app/src/main/java/foundation/e/drive/contentScanner/RemoteFileLister.java b/app/src/main/java/foundation/e/drive/contentScanner/RemoteFileLister.java index 11b18281..f8ae821b 100644 --- a/app/src/main/java/foundation/e/drive/contentScanner/RemoteFileLister.java +++ b/app/src/main/java/foundation/e/drive/contentScanner/RemoteFileLister.java @@ -25,7 +25,6 @@ import foundation.e.drive.database.DbHelper; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.utils.CommonUtils; - /** * Implementation of AbstractFileLister with method adapted to remote content * @author vincent Bourgmayer @@ -138,4 +137,4 @@ public class RemoteFileLister extends AbstractFileLister { return directory; } } -} +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/models/SyncedFileState.java b/app/src/main/java/foundation/e/drive/models/SyncedFileState.java index 927545f6..da09c074 100644 --- a/app/src/main/java/foundation/e/drive/models/SyncedFileState.java +++ b/app/src/main/java/foundation/e/drive/models/SyncedFileState.java @@ -182,8 +182,7 @@ public class SyncedFileState implements Parcelable { public boolean isMediaType() { return isMediaType; } - - + /** * Return in which context the file can scan * @return 0: not scannable. 1: scannable on ecloud. 2: scannable on device. 3: scannable everywhere @@ -192,7 +191,6 @@ public class SyncedFileState implements Parcelable { return scannable; } - @Override public String toString(){ return "SyncedFileState :" @@ -218,4 +216,4 @@ public class SyncedFileState implements Parcelable { public void setUnsyncable() { this.scannable = NOT_SCANNABLE; } -} +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/services/ObserverService.java b/app/src/main/java/foundation/e/drive/services/ObserverService.java index c1f08443..cc943ad5 100644 --- a/app/src/main/java/foundation/e/drive/services/ObserverService.java +++ b/app/src/main/java/foundation/e/drive/services/ObserverService.java @@ -391,4 +391,4 @@ public class ObserverService extends Service implements OnRemoteOperationListene public IBinder onBind(@Nullable Intent intent) { throw new UnsupportedOperationException(); } -} +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/utils/FileDiffUtils.java b/app/src/main/java/foundation/e/drive/utils/FileDiffUtils.java index 59bc0d9e..a9de67c0 100644 --- a/app/src/main/java/foundation/e/drive/utils/FileDiffUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/FileDiffUtils.java @@ -97,4 +97,4 @@ public class FileDiffUtils { // remoteFile.getSize() : getSize() is equal to getLength() except that for folder is also sum the content of the folder! return remoteFile.getSize() == localFile.length(); } -} +} \ No newline at end of file -- GitLab From d7a4bc708c310002b7b7fd98975df434695a5968 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Fri, 2 Jun 2023 11:26:22 +0200 Subject: [PATCH 05/11] implement Test case #182: disable remote file deletion after local file deletion --- .../foundation/e/drive/FileObservers/FileEventListener.java | 6 ++++-- .../e/drive/contentScanner/LocalContentScanner.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java index 4e2bbd2b..19fd5011 100644 --- a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java +++ b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java @@ -8,6 +8,7 @@ package foundation.e.drive.FileObservers; +import static foundation.e.drive.models.SyncRequest.Type.DISABLE_SYNCING; import static foundation.e.drive.models.SyncRequest.Type.REMOTE_DELETE; import static foundation.e.drive.models.SyncRequest.Type.UPLOAD; @@ -229,8 +230,9 @@ public class FileEventListener { //If already in DB if (fileState.getScannable() > 0) { - SyncRequest deleteRequest = new SyncRequest(fileState, REMOTE_DELETE); - this.sendSyncRequestToSynchronizationService(deleteRequest); + //todo: if file is already sync disabled, we should probably remove file from DB + final SyncRequest disableSyncingRequest = new SyncRequest(fileState, DISABLE_SYNCING); + this.sendSyncRequestToSynchronizationService(disableSyncingRequest); } } diff --git a/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java b/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java index 99d8735a..92e33216 100644 --- a/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java +++ b/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java @@ -44,9 +44,9 @@ public class LocalContentScanner extends AbstractContentScanner{ Timber.d("Expected %s to be missing. but it still exists", file.getAbsolutePath()); return; } - + //todo: should we check if already sync disabled, and then remove it from DB ? Timber.d("Add remove SyncRequest for file %s", file.getAbsolutePath()); - syncRequests.put(fileState.getId(), new SyncRequest(fileState, SyncRequest.Type.REMOTE_DELETE)); + syncRequests.put(fileState.getId(), new SyncRequest(fileState, SyncRequest.Type.DISABLE_SYNCING)); } @Override -- GitLab From cd19bf86779cf955d2dddb8ae972ac33c636da87 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 5 Jun 2023 17:44:54 +0200 Subject: [PATCH 06/11] remove useless import --- .../foundation/e/drive/FileObservers/FileEventListener.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java index 19fd5011..d2063248 100644 --- a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java +++ b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java @@ -9,11 +9,9 @@ package foundation.e.drive.FileObservers; import static foundation.e.drive.models.SyncRequest.Type.DISABLE_SYNCING; -import static foundation.e.drive.models.SyncRequest.Type.REMOTE_DELETE; import static foundation.e.drive.models.SyncRequest.Type.UPLOAD; import android.content.Context; -import android.content.Intent; import android.os.FileObserver; import androidx.annotation.NonNull; @@ -26,7 +24,6 @@ import foundation.e.drive.database.DbHelper; import foundation.e.drive.models.SyncRequest; import foundation.e.drive.models.SyncedFileState; import foundation.e.drive.models.SyncedFolder; -import foundation.e.drive.services.SynchronizationService; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.SynchronizationServiceConnection; import timber.log.Timber; -- GitLab From 8bd608d558d6334c31751afe689b278d86728f31 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 6 Jun 2023 16:01:50 +0200 Subject: [PATCH 07/11] remove recycle bin creationg at initialization --- .../java/foundation/e/drive/services/InitializerService.java | 5 ----- app/src/main/java/foundation/e/drive/utils/AppConstants.java | 2 -- 2 files changed, 7 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 93ddb453..bedd7e05 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -110,14 +110,9 @@ public class InitializerService extends Service { */ private void start() { Timber.d("start()"); - CommonUtils.registerPeriodicUserInfoChecking(WorkManager.getInstance(this)); final List syncedFolders = RootSyncedFolderProvider.INSTANCE.getSyncedFolderRoots(getApplicationContext()); - - final boolean recycleBinCreated = new File(AppConstants.RECYCLE_BIN_PATH).mkdirs(); - if (!recycleBinCreated) Timber.w("Cannot create recycle bin. It may be already existing"); - CommonUtils.registerInitializationWorkers(syncedFolders, WorkManager.getInstance(getApplicationContext()) ); } diff --git a/app/src/main/java/foundation/e/drive/utils/AppConstants.java b/app/src/main/java/foundation/e/drive/utils/AppConstants.java index 0d907fc3..1c9da75a 100644 --- a/app/src/main/java/foundation/e/drive/utils/AppConstants.java +++ b/app/src/main/java/foundation/e/drive/utils/AppConstants.java @@ -50,8 +50,6 @@ public abstract class AppConstants { public static final String WORK_INITIALIZATION_TAG = "eDrive-init"; public static final String USER_AGENT = "eos(" + getBuildTime() + ")-eDrive(" + BuildConfig.VERSION_NAME + ")"; - public static final String RECYCLE_BIN_PATH = Environment.getExternalStorageDirectory() + PATH_SEPARATOR + "Sync trash"; - /** * Get a readable OS's build date String * -- GitLab From 7a3c4ab2df6c9a7c0d4c3b9a05788c918ba2f45c Mon Sep 17 00:00:00 2001 From: Vincent Bourgmayer Date: Wed, 7 Jun 2023 09:27:14 +0000 Subject: [PATCH 08/11] Remove linter rule which is not the good solution --- lint.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/lint.xml b/lint.xml index 64b52e02..61366ae3 100644 --- a/lint.xml +++ b/lint.xml @@ -5,7 +5,6 @@ - -- GitLab From 9fa54eabef52a0dfaad93f50cf350307e3c3e3d9 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 7 Jun 2023 15:06:46 +0200 Subject: [PATCH 09/11] replace raw value for scannable value of synced file state by const --- .../FileObservers/FileEventListener.java | 13 +++++++----- .../contentScanner/LocalContentScanner.java | 12 +++++++---- .../contentScanner/RemoteContentScanner.java | 11 ++++++---- .../e/drive/services/InitializerService.java | 1 - .../LocalContentScannerTest.java | 14 +++++++------ .../contentScanner/LocalFileListerTest.java | 6 ++++-- .../RemoteContentScannerTest.java | 20 ++++++++++--------- .../contentScanner/RemoteFileListerTest.java | 6 ++++-- .../database/SyncedFileStateDAOTest.java | 4 +++- .../operations/UploadFileOperationTest.java | 12 ++++++----- 10 files changed, 60 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java index d2063248..e7f296ba 100644 --- a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java +++ b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java @@ -10,6 +10,9 @@ package foundation.e.drive.FileObservers; import static foundation.e.drive.models.SyncRequest.Type.DISABLE_SYNCING; import static foundation.e.drive.models.SyncRequest.Type.UPLOAD; +import static foundation.e.drive.models.SyncedFileState.DEVICE_SCANNABLE; +import static foundation.e.drive.models.SyncedFileState.ECLOUD_SCANNABLE; +import static foundation.e.drive.models.SyncedFileState.NOT_SCANNABLE; import android.content.Context; import android.os.FileObserver; @@ -187,10 +190,10 @@ public class FileEventListener { Timber.d("Won't send sync request: no parent are known for new file: %s", file.getName()); return; } - int scannableValue = 0; + int scannableValue = NOT_SCANNABLE; if (parentFolder.isEnabled()) { - if (parentFolder.isScanRemote()) scannableValue++; - if (parentFolder.isScanLocal()) scannableValue += 2; + if (parentFolder.isScanRemote()) scannableValue += ECLOUD_SCANNABLE; + if (parentFolder.isScanLocal()) scannableValue += DEVICE_SCANNABLE; } final String remotePath = parentFolder.getRemoteFolder()+file.getName(); @@ -204,7 +207,7 @@ public class FileEventListener { } } else { //File update final boolean isWaitingForDownload = fileState.isLastEtagStored() && fileState.getLocalLastModified() == 0L; - if (fileState.getScannable() > 1 && !isWaitingForDownload) { + if (fileState.getScannable() > ECLOUD_SCANNABLE && !isWaitingForDownload) { request = new SyncRequest(fileState, UPLOAD); } } @@ -226,7 +229,7 @@ public class FileEventListener { } //If already in DB - if (fileState.getScannable() > 0) { + if (fileState.getScannable() > NOT_SCANNABLE) { //todo: if file is already sync disabled, we should probably remove file from DB final SyncRequest disableSyncingRequest = new SyncRequest(fileState, DISABLE_SYNCING); this.sendSyncRequestToSynchronizationService(disableSyncingRequest); diff --git a/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java b/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java index 92e33216..5b4a7be4 100644 --- a/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java +++ b/app/src/main/java/foundation/e/drive/contentScanner/LocalContentScanner.java @@ -7,6 +7,10 @@ */ package foundation.e.drive.contentScanner; +import static foundation.e.drive.models.SyncedFileState.DEVICE_SCANNABLE; +import static foundation.e.drive.models.SyncedFileState.ECLOUD_SCANNABLE; +import static foundation.e.drive.models.SyncedFileState.NOT_SCANNABLE; + import android.content.Context; import androidx.annotation.NonNull; @@ -55,10 +59,10 @@ public class LocalContentScanner extends AbstractContentScanner{ final SyncedFolder parentDir = getParentSyncedFolder(filePath); if (parentDir == null) return; - int scannableValue = 0; + int scannableValue = NOT_SCANNABLE; if (parentDir.isEnabled()) { - if (parentDir.isScanRemote()) scannableValue++; - if (parentDir.isScanLocal()) scannableValue += 2; + if (parentDir.isScanRemote()) scannableValue += ECLOUD_SCANNABLE; + if (parentDir.isScanLocal()) scannableValue += DEVICE_SCANNABLE; } final SyncedFileState newSyncedFileState = new SyncedFileState(-1, file.getName(), filePath, parentDir.getRemoteFolder() + file.getName(), "", 0, parentDir.getId(), parentDir.isMediaType(),scannableValue); @@ -73,7 +77,7 @@ public class LocalContentScanner extends AbstractContentScanner{ @Override protected void onKnownFileFound(@NonNull File file, @NonNull SyncedFileState fileState) { - if (fileState.getScannable() == SyncedFileState.NOT_SCANNABLE) return; + if (fileState.getScannable() == NOT_SCANNABLE) return; if (FileDiffUtils.getActionForFileDiff(file, fileState) == FileDiffUtils.Action.Upload) { Timber.d("Add upload SyncRequest for %s", file.getAbsolutePath()); diff --git a/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java b/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java index f64c010f..dcf48db7 100644 --- a/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java +++ b/app/src/main/java/foundation/e/drive/contentScanner/RemoteContentScanner.java @@ -8,6 +8,9 @@ package foundation.e.drive.contentScanner; import static foundation.e.drive.models.SyncRequest.Type.DISABLE_SYNCING; +import static foundation.e.drive.models.SyncedFileState.DEVICE_SCANNABLE; +import static foundation.e.drive.models.SyncedFileState.ECLOUD_SCANNABLE; +import static foundation.e.drive.models.SyncedFileState.NOT_SCANNABLE; import static foundation.e.drive.utils.FileDiffUtils.getActionForFileDiff; import android.content.Context; @@ -43,7 +46,7 @@ public class RemoteContentScanner extends AbstractContentScanner { @Override protected void onKnownFileFound(@NonNull RemoteFile file, @NonNull SyncedFileState fileState) { - if (fileState.getScannable() == SyncedFileState.NOT_SCANNABLE) return; + if (fileState.getScannable() == NOT_SCANNABLE) return; final FileDiffUtils.Action action = getActionForFileDiff(file, fileState); if (action == FileDiffUtils.Action.Download) { @@ -68,10 +71,10 @@ public class RemoteContentScanner extends AbstractContentScanner { final String fileName = CommonUtils.getFileNameFromPath(remoteFilePath); - int scannableValue = 0; + int scannableValue = NOT_SCANNABLE; if (parentDir.isEnabled()) { - if (parentDir.isScanRemote()) scannableValue++; - if (parentDir.isScanLocal()) scannableValue += 2; + if (parentDir.isScanRemote()) scannableValue += ECLOUD_SCANNABLE; + if (parentDir.isScanLocal()) scannableValue += DEVICE_SCANNABLE; } final SyncedFileState newFileState = new SyncedFileState(-1, fileName, parentDir.getLocalFolder() + fileName, remoteFilePath, file.getEtag(), 0, parentDir.getId(), parentDir.isMediaType(), scannableValue); diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index bedd7e05..74927399 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -106,7 +106,6 @@ public class InitializerService extends Service { * Set up base component for eDrive: * - Register basic worker * - build root folders to sync - * - Create Recycle bin for eDrive */ private void start() { Timber.d("start()"); diff --git a/app/src/test/java/foundation/e/drive/contentScanner/LocalContentScannerTest.java b/app/src/test/java/foundation/e/drive/contentScanner/LocalContentScannerTest.java index 118dd6a2..9bab7386 100644 --- a/app/src/test/java/foundation/e/drive/contentScanner/LocalContentScannerTest.java +++ b/app/src/test/java/foundation/e/drive/contentScanner/LocalContentScannerTest.java @@ -10,6 +10,8 @@ package foundation.e.drive.contentScanner; import static org.mockito.Mockito.when; +import static foundation.e.drive.models.SyncedFileState.ALL_SCANNABLE; + import android.content.Context; import android.os.Build; @@ -63,8 +65,8 @@ public class LocalContentScannerTest { final List localFiles = new ArrayList<>(); final List syncedFileStates = new ArrayList<>(); - final SyncedFileState syncedFileState1 = new SyncedFileState(1, "titi.png", "local/path/titi.png", "remote/path/titi.png", "aaaa", 123456, 0, true, 3); - final SyncedFileState syncedFileState2 = new SyncedFileState(2, "tutu.png", "local/path/tutu.png", "remote/path/tutu.png", "bbbb", 234567, 0, true, 3); + final SyncedFileState syncedFileState1 = new SyncedFileState(1, "titi.png", "local/path/titi.png", "remote/path/titi.png", "aaaa", 123456, 0, true, ALL_SCANNABLE); + final SyncedFileState syncedFileState2 = new SyncedFileState(2, "tutu.png", "local/path/tutu.png", "remote/path/tutu.png", "bbbb", 234567, 0, true, ALL_SCANNABLE); syncedFileStates.add(syncedFileState1); syncedFileStates.add(syncedFileState2); @@ -86,8 +88,8 @@ public class LocalContentScannerTest { localFiles.add(file2); final List syncedFileStates = new ArrayList<>(); - final SyncedFileState syncedFileState1 = new SyncedFileState(1, file1.getName(), file1.getAbsolutePath(), "remote/path/titi.png", "", 0, 0, true, 3); - final SyncedFileState syncedFileState2 = new SyncedFileState(2, file2.getName(), file2.getAbsolutePath(), "remote/path/tutu.png", "", 0, 0, true, 3); + final SyncedFileState syncedFileState1 = new SyncedFileState(1, file1.getName(), file1.getAbsolutePath(), "remote/path/titi.png", "", 0, 0, true, ALL_SCANNABLE); + final SyncedFileState syncedFileState2 = new SyncedFileState(2, file2.getName(), file2.getAbsolutePath(), "remote/path/tutu.png", "", 0, 0, true, ALL_SCANNABLE); syncedFileStates.add(syncedFileState1); syncedFileStates.add(syncedFileState2); @@ -110,8 +112,8 @@ public class LocalContentScannerTest { localFiles.add(file2); final List syncedFileStates = new ArrayList<>(); - final SyncedFileState syncedFileState1 = new SyncedFileState(1, file1.getName(), file1.getAbsolutePath(), "remote/path/titi.png", "aaaa", 123456, 0, true, 3); - final SyncedFileState syncedFileState2 = new SyncedFileState(2, file2.getName(), file2.getAbsolutePath(), "remote/path/tutu.png", "bbbb", 234567, 0, true, 3); + final SyncedFileState syncedFileState1 = new SyncedFileState(1, file1.getName(), file1.getAbsolutePath(), "remote/path/titi.png", "aaaa", 123456, 0, true, ALL_SCANNABLE); + final SyncedFileState syncedFileState2 = new SyncedFileState(2, file2.getName(), file2.getAbsolutePath(), "remote/path/tutu.png", "bbbb", 234567, 0, true, ALL_SCANNABLE); syncedFileStates.add(syncedFileState1); syncedFileStates.add(syncedFileState2); diff --git a/app/src/test/java/foundation/e/drive/contentScanner/LocalFileListerTest.java b/app/src/test/java/foundation/e/drive/contentScanner/LocalFileListerTest.java index ee0d7b75..83c7d324 100644 --- a/app/src/test/java/foundation/e/drive/contentScanner/LocalFileListerTest.java +++ b/app/src/test/java/foundation/e/drive/contentScanner/LocalFileListerTest.java @@ -8,6 +8,8 @@ package foundation.e.drive.contentScanner; +import static foundation.e.drive.models.SyncedFileState.ALL_SCANNABLE; + import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.os.Build; @@ -145,7 +147,7 @@ public class LocalFileListerTest { final File directory = Mockito.spy(testRootDirectory); Mockito.when(directory.lastModified()).thenReturn(lastModified); - final SyncedFileState dummy = new SyncedFileState(6, "foo.jpg", dirPath + "foo.jpg", "/remote/path/test/foo.jpg", "", 0L, 12, true, 3); + final SyncedFileState dummy = new SyncedFileState(6, "foo.jpg", dirPath + "foo.jpg", "/remote/path/test/foo.jpg", "", 0L, 12, true, ALL_SCANNABLE); DbHelper.manageSyncedFileStateDB(dummy, "INSERT", context); final SyncedFolder syncedFolder = new SyncedFolder("any", dirPath , "/remote/path/test/", true, true, true, true); @@ -182,7 +184,7 @@ public class LocalFileListerTest { syncedFolder.setId(12); syncedFolder.setLastModified(123456L); - final SyncedFileState dummy = new SyncedFileState(6, "foo.jpg", dirPath + "foo.jpg", "/remote/path/test/foo.jpg", "", 0L, 12, true, 3); + final SyncedFileState dummy = new SyncedFileState(6, "foo.jpg", dirPath + "foo.jpg", "/remote/path/test/foo.jpg", "", 0L, 12, true, ALL_SCANNABLE); DbHelper.manageSyncedFileStateDB(dummy, "INSERT", context); final boolean skip = fileListerUnderTest.skipDirectory(directory, syncedFolder, context); diff --git a/app/src/test/java/foundation/e/drive/contentScanner/RemoteContentScannerTest.java b/app/src/test/java/foundation/e/drive/contentScanner/RemoteContentScannerTest.java index 9375919c..192cf38d 100644 --- a/app/src/test/java/foundation/e/drive/contentScanner/RemoteContentScannerTest.java +++ b/app/src/test/java/foundation/e/drive/contentScanner/RemoteContentScannerTest.java @@ -9,6 +9,8 @@ package foundation.e.drive.contentScanner; import static org.junit.Assert.assertEquals; +import static foundation.e.drive.models.SyncedFileState.ALL_SCANNABLE; + import android.content.Context; import android.os.Build; @@ -85,9 +87,9 @@ public class RemoteContentScannerTest { Assert.assertTrue("Fake list of cloud Content is not empty", cloudContent.isEmpty()); final List dbContent = new ArrayList<>(); - dbContent.add(new SyncedFileState(5, "toto", "local/path/toto", "remote/path/toto", "5555", 22222, 2, true, 3)); - dbContent.add(new SyncedFileState(3, "titi", "local/path/titi", "remote/path/titi", "5556", 22322, 2, true, 3)); - dbContent.add(new SyncedFileState(2, "tata", "local/path/tata", "remote/path/tata", "5557", 22232, 2, true, 3)); + dbContent.add(new SyncedFileState(5, "toto", "local/path/toto", "remote/path/toto", "5555", 22222, 2, true, ALL_SCANNABLE)); + dbContent.add(new SyncedFileState(3, "titi", "local/path/titi", "remote/path/titi", "5556", 22322, 2, true, ALL_SCANNABLE)); + dbContent.add(new SyncedFileState(2, "tata", "local/path/tata", "remote/path/tata", "5557", 22232, 2, true, ALL_SCANNABLE)); Assert.assertFalse("List of SyncedFileState is empty", dbContent.isEmpty()); @@ -145,9 +147,9 @@ public class RemoteContentScannerTest { final List dbContent = new ArrayList<>(); - dbContent.add(new SyncedFileState(5, "toto", "local/path/toto", "remote/path/toto", "5555", 22222, 2, true, 3)); - dbContent.add(new SyncedFileState(3, "titi", "local/path/titi", "remote/path/titi", "5556", 22322, 2, true, 3)); - dbContent.add(new SyncedFileState(2, "tata", "local/path/tata", "remote/path/tata", "5557", 22232, 2, true, 3)); + dbContent.add(new SyncedFileState(5, "toto", "local/path/toto", "remote/path/toto", "5555", 22222, 2, true, ALL_SCANNABLE)); + dbContent.add(new SyncedFileState(3, "titi", "local/path/titi", "remote/path/titi", "5556", 22322, 2, true, ALL_SCANNABLE)); + dbContent.add(new SyncedFileState(2, "tata", "local/path/tata", "remote/path/tata", "5557", 22232, 2, true, ALL_SCANNABLE)); Assert.assertFalse("List of SyncedFileState is empty", dbContent.isEmpty()); @@ -183,9 +185,9 @@ public class RemoteContentScannerTest { final List dbContent = new ArrayList<>(); - dbContent.add(new SyncedFileState(5, "toto", "local/path/toto", "remote/path/toto", "5555", 22222, 2, true, 3)); - dbContent.add(new SyncedFileState(3, "titi", "local/path/titi", "remote/path/titi", "5556", 22322, 2, true, 3)); - dbContent.add(new SyncedFileState(2, "tata", "local/path/tata", "remote/path/tata", "5557", 22232, 2, true, 3)); + dbContent.add(new SyncedFileState(5, "toto", "local/path/toto", "remote/path/toto", "5555", 22222, 2, true, ALL_SCANNABLE)); + dbContent.add(new SyncedFileState(3, "titi", "local/path/titi", "remote/path/titi", "5556", 22322, 2, true, ALL_SCANNABLE)); + dbContent.add(new SyncedFileState(2, "tata", "local/path/tata", "remote/path/tata", "5557", 22232, 2, true, ALL_SCANNABLE)); Assert.assertFalse("List of SyncedFileState is empty", dbContent.isEmpty()); diff --git a/app/src/test/java/foundation/e/drive/contentScanner/RemoteFileListerTest.java b/app/src/test/java/foundation/e/drive/contentScanner/RemoteFileListerTest.java index 80be7075..235cddf5 100644 --- a/app/src/test/java/foundation/e/drive/contentScanner/RemoteFileListerTest.java +++ b/app/src/test/java/foundation/e/drive/contentScanner/RemoteFileListerTest.java @@ -10,6 +10,8 @@ package foundation.e.drive.contentScanner; import static org.mockito.Mockito.when; +import static foundation.e.drive.models.SyncedFileState.ALL_SCANNABLE; + import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; @@ -215,7 +217,7 @@ public class RemoteFileListerTest { syncedFolder.setId(12); syncedFolder.setLastEtag("5555aaaa"); - final SyncedFileState dummy = new SyncedFileState(6, "foo.jpg", "local/foo.jpg", TEST_FILE_TREE_ROOT_PATH + "foo.jpg", "7777", 0L, 12, true, 3); + final SyncedFileState dummy = new SyncedFileState(6, "foo.jpg", "local/foo.jpg", TEST_FILE_TREE_ROOT_PATH + "foo.jpg", "7777", 0L, 12, true, ALL_SCANNABLE); DbHelper.manageSyncedFileStateDB(dummy, "INSERT", context); final boolean skip = fileListerUnderTest.skipDirectory(remoteFile, syncedFolder, context); @@ -231,7 +233,7 @@ public class RemoteFileListerTest { syncedFolder.setId(12); syncedFolder.setLastEtag("5555aaaa"); - final SyncedFileState dummy = new SyncedFileState(6, "foo.jpg", "local/foo.jpg", TEST_FILE_TREE_ROOT_PATH + "foo.jpg", "7777", 0L, 12, true, 3); + final SyncedFileState dummy = new SyncedFileState(6, "foo.jpg", "local/foo.jpg", TEST_FILE_TREE_ROOT_PATH + "foo.jpg", "7777", 0L, 12, true, ALL_SCANNABLE); DbHelper.manageSyncedFileStateDB(dummy, "INSERT", context); final boolean skip = fileListerUnderTest.skipDirectory(remoteFile, syncedFolder, context); diff --git a/app/src/test/java/foundation/e/drive/database/SyncedFileStateDAOTest.java b/app/src/test/java/foundation/e/drive/database/SyncedFileStateDAOTest.java index a954e22b..cd301b12 100644 --- a/app/src/test/java/foundation/e/drive/database/SyncedFileStateDAOTest.java +++ b/app/src/test/java/foundation/e/drive/database/SyncedFileStateDAOTest.java @@ -8,6 +8,8 @@ package foundation.e.drive.database; +import static foundation.e.drive.models.SyncedFileState.ALL_SCANNABLE; + import android.content.Context; import android.os.Build; @@ -49,7 +51,7 @@ public class SyncedFileStateDAOTest { dummyFolder.setId(12); DbHelper.insertSyncedFolder(dummyFolder, context); - final SyncedFileState dummy = new SyncedFileState(6, "foo.jpg", "local/foo.jpg", "remote/foo.jpg", "7777", 0L, 12, true, 3); + final SyncedFileState dummy = new SyncedFileState(6, "foo.jpg", "local/foo.jpg", "remote/foo.jpg", "7777", 0L, 12, true, ALL_SCANNABLE); DbHelper.manageSyncedFileStateDB(dummy, "INSERT", context); daoUnderTest = DbHelper.openSyncedFileStateDAO(context, false); diff --git a/app/src/test/java/foundation/e/drive/operations/UploadFileOperationTest.java b/app/src/test/java/foundation/e/drive/operations/UploadFileOperationTest.java index 28d9f1d3..eb8d67bf 100644 --- a/app/src/test/java/foundation/e/drive/operations/UploadFileOperationTest.java +++ b/app/src/test/java/foundation/e/drive/operations/UploadFileOperationTest.java @@ -7,6 +7,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static foundation.e.drive.models.SyncedFileState.ALL_SCANNABLE; + import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; @@ -108,7 +110,7 @@ public class UploadFileOperationTest { "dummy.txt", TestUtils.TEST_LOCAL_ROOT_FOLDER_PATH + "small/dummy.txt", TestUtils.TEST_REMOTE_ROOT_FOLDER_PATH + "small/dummy.txt", - "", 0L, 0, true, 3); + "", 0L, 0, true, ALL_SCANNABLE); sfs.setId(DbHelper.manageSyncedFileStateDB(sfs, "INSERT", context)); syncedFileStates.add(sfs); @@ -246,7 +248,7 @@ public class UploadFileOperationTest { 11111220, 1, false, - 3); + ALL_SCANNABLE); assertFalse("SyncedFileState should not have a media type but it has", testSyncedState.isMediaType()); @@ -265,7 +267,7 @@ public class UploadFileOperationTest { 11111220, 1, true, - 3); + ALL_SCANNABLE); assertTrue("SyncedFileState's ETag should be empty but isn't", testSyncedState.getLastETAG().isEmpty()); assertTrue("SyncedFileState is not a media type but it should", testSyncedState.isMediaType()); @@ -284,7 +286,7 @@ public class UploadFileOperationTest { 11111220, 1, true, - 3); + ALL_SCANNABLE); assertFalse("SyncedFileState's ETag should not be empty but isn't", testSyncedState.getLastETAG().isEmpty()); assertTrue("SyncedFileState is not a media type but it should", testSyncedState.isMediaType()); @@ -304,7 +306,7 @@ public class UploadFileOperationTest { 11111220, 1, true, - 3); + ALL_SCANNABLE); assertFalse("SyncedFileState's ETag should not be empty but isn't", testSyncedState.getLastETAG().isEmpty()); assertTrue("SyncedFileState is not a media type but it should", testSyncedState.isMediaType()); -- GitLab From aafdf74b41d42d66bc8c09a826b7f530ee7403bd Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Thu, 8 Jun 2023 07:53:56 +0000 Subject: [PATCH 10/11] Apply 1 suggestion(s) to 1 file(s) --- .../foundation/e/drive/FileObservers/FileEventListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java index e7f296ba..153c7886 100644 --- a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java +++ b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java @@ -192,7 +192,7 @@ public class FileEventListener { } int scannableValue = NOT_SCANNABLE; if (parentFolder.isEnabled()) { - if (parentFolder.isScanRemote()) scannableValue += ECLOUD_SCANNABLE; + if (parentFolder.isScanRemote()) scannableValue = ECLOUD_SCANNABLE; if (parentFolder.isScanLocal()) scannableValue += DEVICE_SCANNABLE; } -- GitLab From f2f6b345a03c28c2913b77700e4600d5c3c9d671 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 8 Jun 2023 08:26:17 +0000 Subject: [PATCH 11/11] Apply 1 suggestion(s) to 1 file(s) --- .../foundation/e/drive/services/SynchronizationService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java index 0cf78b77..de91978f 100644 --- a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java +++ b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java @@ -249,7 +249,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation Timber.v(" starts " + request.getSyncedFileState().getName() + " local deletion on thread " + threadIndex); final FileSyncDisabler fileSyncDisabler = new FileSyncDisabler(request.getSyncedFileState()); - threadPool[threadIndex] = new Thread(fileSyncDisabler.getRunnable( handler, threadIndex, getApplicationContext(), this)); + threadPool[threadIndex] = new Thread(fileSyncDisabler.getRunnable(handler, threadIndex, getApplicationContext(), this)); threadPool[threadIndex].start(); startedSync.put(threadIndex, syncWrapper); return; -- GitLab