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 4e2bbd2bdae100f94736f3ab2ae49be09559d862..153c788622105d5ba2082995fd627cc307b32580 100644 --- a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java +++ b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java @@ -8,11 +8,13 @@ package foundation.e.drive.FileObservers; -import static foundation.e.drive.models.SyncRequest.Type.REMOTE_DELETE; +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.content.Intent; import android.os.FileObserver; import androidx.annotation.NonNull; @@ -25,7 +27,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; @@ -189,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(); @@ -206,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); } } @@ -228,9 +229,10 @@ public class FileEventListener { } //If already in DB - if (fileState.getScannable() > 0) { - SyncRequest deleteRequest = new SyncRequest(fileState, REMOTE_DELETE); - this.sendSyncRequestToSynchronizationService(deleteRequest); + 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/RecycleBin.kt b/app/src/main/java/foundation/e/drive/RecycleBin.kt deleted file mode 100644 index 447106bbf12db6f6f755bf326bafa90a055adb16..0000000000000000000000000000000000000000 --- 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/AbstractContentScanner.java b/app/src/main/java/foundation/e/drive/contentScanner/AbstractContentScanner.java index f2cce7457822f3b3b193a23c3fb10daf42e5ecf2..bdf4606bfc617d7aa4d9d199216e879791c983df 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 dbc5864c5bce4c3e17c7754ac2eb40865fdacf6f..5b4a7be42060ae4e159a58cee21bf3a57dc50355 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; @@ -44,9 +48,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 @@ -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,6 +77,8 @@ public class LocalContentScanner extends AbstractContentScanner{ @Override protected void onKnownFileFound(@NonNull File file, @NonNull SyncedFileState fileState) { + if (fileState.getScannable() == 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 37b1ffc5883a8e58a6a7aadcc73938116238400e..dcf48db76ef3b036a3380244d01727101f43deca 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,10 @@ */ 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.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,6 +46,8 @@ public class RemoteContentScanner extends AbstractContentScanner { @Override protected void onKnownFileFound(@NonNull RemoteFile file, @NonNull SyncedFileState fileState) { + if (fileState.getScannable() == NOT_SCANNABLE) return; + final FileDiffUtils.Action action = getActionForFileDiff(file, fileState); if (action == FileDiffUtils.Action.Download) { @@ -66,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); @@ -88,8 +93,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/contentScanner/RemoteFileLister.java b/app/src/main/java/foundation/e/drive/contentScanner/RemoteFileLister.java index 11b18281840d8fe8adfe688f83dd7b986c344148..f8ae821bb47129c22298e6b8adfbaf0de4983354 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/database/DbHelper.java b/app/src/main/java/foundation/e/drive/database/DbHelper.java index ae0b3033e59967516c2d6fc445f2a7fd95b29b78..a71ca586d39877c9fc988688d0465bdbe8ad5498 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 9716201fae600d9baf4ae8d6af956b936a7d679a..9af36d51a57c85be9b92575a00f35ac33410dfde 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 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 239217d17c2639ec51ae3b2f05a434886f1aa3e5..73f465627bdf1e4a13ca03c5ff933d5e03db2823 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 0c07ddc9b629ed5827de49edcbaa2efaca2ddd25..da09c0749acd58e5bad7a96de06a2be0e31a2dfd 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 :" @@ -211,4 +209,11 @@ public class SyncedFileState implements Parcelable { public int describeContents() { return 0; } -} + + /** + * Disable syncing of the concerned file + */ + public void setUnsyncable() { + this.scannable = NOT_SCANNABLE; + } +} \ No newline at end of file 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 93ddb453bbcc7bec3e42f24b44c0785e418fc214..7492739990b54bd593eceb2747fd8acb6b3b70ec 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -106,18 +106,12 @@ 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()"); - 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/services/ObserverService.java b/app/src/main/java/foundation/e/drive/services/ObserverService.java index c1f084433c2950bd0eb8f7b80a8ac751fc5a91f5..cc943ad527fc773e300a895bed77d4ed8c73b631 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/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java index 92df659f3c3db046b0a6d30b931c709df7df88e2..de91978f1704a1857a9388450024289db7ab58a8 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/AppConstants.java b/app/src/main/java/foundation/e/drive/utils/AppConstants.java index 0d907fc37a1f13b464f65b80a487e732363054b7..1c9da75aee7f025396c2f1748e07479223997536 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 * 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 86e67971a8bc6efe2a4d13d6361d09d07ff82b8d..1ffb3a1ec3c21f81e9d30dd9377b22198e1cbc65 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/utils/FileDiffUtils.java b/app/src/main/java/foundation/e/drive/utils/FileDiffUtils.java index 59bc0d9e215dc98adba7d80592bd2e8b705c6104..a9de67c0bc17d81f26f8c109036865ac15dcb020 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 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 0000000000000000000000000000000000000000..7b883737d100884f6c05b03334c77a728a6e2f73 --- /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 5890e103e6c450b5ff71fe13f3a01363f2dce8cc..7cdbf4f15c6eb94fde151eec34e1b7d64a148d60 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 ad6b36d88cd7f1f50ec008cc281dc92134657dfa..0000000000000000000000000000000000000000 --- 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 45328ed3589a82b870153b36ebee9c798d234632..0000000000000000000000000000000000000000 --- 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 1e16cab43743ad8fe1a66a68878abc78123338b4..6331f302873ee2089349408b903dac86cc22fa56 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/LocalContentScannerTest.java b/app/src/test/java/foundation/e/drive/contentScanner/LocalContentScannerTest.java index 118dd6a24bd509888f0191afd49ba06959414f11..9bab73864255a27a7ebf9bbcbbe5846d3e4ab003 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 ee0d7b75692b9c4357da686aef73cefca8d0fa44..83c7d3248d0d3bb0c1662c650ad4611bbbe4856e 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 ae291d142ad98c460f753647c765780cf0b10e85..192cf38d7ea29b7f362cdb66905d528c1c386715 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()); @@ -96,7 +98,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()); } } @@ -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 80be707544907ff7962f8405bcf869cdf6920c93..235cddf52e7d9363fe3d75e6a60843301ac7bc56 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 a954e22ba2f3de51ac885f0d146d7a3b93343324..cd301b120ed18ce2323198dbdd5eb5f6021cbd88 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 28d9f1d3619766084d3a2588d6dda8f8e6f579f2..eb8d67bf1a8b8d0c4a5b7f3df90ee71f2df00fb7 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()); diff --git a/lint.xml b/lint.xml index 8f925319c1e5c16829785e3824f6742fa5acb434..61366ae37eb75b7e206d05d27ee0183306551c9a 100644 --- a/lint.xml +++ b/lint.xml @@ -5,7 +5,7 @@ - +