Browse Source

For SyncOperation FileDataStorageManager is required, therefore this is now part of constructor, whereas it before was only part of .execute()

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 3 years ago
parent
commit
02eb42e42a
41 changed files with 467 additions and 418 deletions
  1. 8 5
      src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java
  2. 4 4
      src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.java
  3. 15 14
      src/androidTest/java/com/owncloud/android/AbstractIT.java
  4. 13 12
      src/androidTest/java/com/owncloud/android/AbstractOnServerIT.java
  5. 3 2
      src/androidTest/java/com/owncloud/android/DownloadIT.java
  6. 8 7
      src/androidTest/java/com/owncloud/android/FileIT.java
  7. 2 2
      src/androidTest/java/com/owncloud/android/ScreenshotsIT.java
  8. 71 64
      src/androidTest/java/com/owncloud/android/UploadIT.java
  9. 22 16
      src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt
  10. 13 9
      src/androidTest/java/com/owncloud/android/operations/RemoveFileOperationIT.java
  11. 10 2
      src/androidTest/java/com/owncloud/android/util/ErrorMessageAdapterIT.java
  12. 3 2
      src/main/java/com/nextcloud/client/files/downloader/UploadTask.kt
  13. 3 2
      src/main/java/com/nextcloud/client/jobs/OfflineSyncWork.kt
  14. 5 3
      src/main/java/com/owncloud/android/files/services/FileUploader.java
  15. 4 2
      src/main/java/com/owncloud/android/operations/CheckCurrentCredentialsOperation.java
  16. 4 4
      src/main/java/com/owncloud/android/operations/CommentFileOperation.java
  17. 5 2
      src/main/java/com/owncloud/android/operations/CopyFileOperation.java
  18. 4 1
      src/main/java/com/owncloud/android/operations/CreateFolderOperation.java
  19. 4 1
      src/main/java/com/owncloud/android/operations/CreateShareViaLinkOperation.java
  20. 14 7
      src/main/java/com/owncloud/android/operations/CreateShareWithShareeOperation.java
  21. 4 0
      src/main/java/com/owncloud/android/operations/GetCapabilitiesOperation.java
  22. 25 18
      src/main/java/com/owncloud/android/operations/GetSharesForFileOperation.java
  23. 6 1
      src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java
  24. 7 4
      src/main/java/com/owncloud/android/operations/MoveFileOperation.java
  25. 3 5
      src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java
  26. 10 6
      src/main/java/com/owncloud/android/operations/RemoveFileOperation.java
  27. 5 4
      src/main/java/com/owncloud/android/operations/RenameFileOperation.java
  28. 24 18
      src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java
  29. 25 17
      src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java
  30. 10 8
      src/main/java/com/owncloud/android/operations/UnshareOperation.java
  31. 6 3
      src/main/java/com/owncloud/android/operations/UpdateNoteForShareOperation.java
  32. 1 1
      src/main/java/com/owncloud/android/operations/UpdateOCVersionOperation.java
  33. 6 7
      src/main/java/com/owncloud/android/operations/UpdateSharePermissionsOperation.java
  34. 5 2
      src/main/java/com/owncloud/android/operations/UpdateShareViaLinkOperation.java
  35. 21 6
      src/main/java/com/owncloud/android/operations/UploadFileOperation.java
  36. 21 93
      src/main/java/com/owncloud/android/operations/common/SyncOperation.java
  37. 18 10
      src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java
  38. 35 37
      src/main/java/com/owncloud/android/services/OperationsService.java
  39. 2 8
      src/main/java/com/owncloud/android/services/SyncFolderHandler.java
  40. 2 2
      src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java
  41. 16 7
      src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

+ 8 - 5
src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java

@@ -95,7 +95,9 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
 
         if (capability.getVersion().equals(new OwnCloudVersion("0.0.0"))) {
             // fetch new one
-            assertTrue(new GetCapabilitiesOperation().execute(client, getStorageManager()).isSuccess());
+            assertTrue(new GetCapabilitiesOperation(getStorageManager())
+                           .execute(client)
+                           .isSuccess());
         }
         // tests only for NC19+
         assumeTrue(getStorageManager()
@@ -464,8 +466,9 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
                                            false,
                                            account,
                                            false,
-                                           targetContext)
-                       .execute(client, getStorageManager())
+                                           targetContext,
+                                           getStorageManager())
+                       .execute(client)
                        .isSuccess());
     }
 
@@ -614,8 +617,8 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
                 Log_OC.d(this, "Remove file: " + child.getDecryptedRemotePath());
             }
 
-            assertTrue(new RemoveFileOperation(child, false, account, false, targetContext)
-                           .execute(client, getStorageManager())
+            assertTrue(new RemoveFileOperation(child, false, account, false, targetContext, getStorageManager())
+                           .execute(client)
                            .isSuccess()
                       );
         }

+ 4 - 4
src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.java

@@ -135,8 +135,8 @@ public class FileDisplayActivityIT extends AbstractOnServerIT {
         FileDisplayActivity sut = activityRule.launchActivity(null);
 
         // given test folder
-        assertTrue(new CreateFolderOperation("/test/", user, targetContext)
-                       .execute(client, getStorageManager())
+        assertTrue(new CreateFolderOperation("/test/", user, targetContext, getStorageManager())
+                       .execute(client)
                        .isSuccess());
 
         // navigate into it
@@ -162,8 +162,8 @@ public class FileDisplayActivityIT extends AbstractOnServerIT {
     public void switchToGridView() {
         activityRule.launchActivity(null);
 
-        assertTrue(new CreateFolderOperation("/test/", user, targetContext)
-                       .execute(client, getStorageManager())
+        assertTrue(new CreateFolderOperation("/test/", user, targetContext, getStorageManager())
+                       .execute(client)
                        .isSuccess());
 
         Espresso.onView(withId(R.id.switch_grid_view_button)).perform(click());

+ 15 - 14
src/androidTest/java/com/owncloud/android/AbstractIT.java

@@ -312,8 +312,8 @@ public abstract class AbstractIT {
     }
 
     public OCFile createFolder(String remotePath) {
-        TestCase.assertTrue(new CreateFolderOperation(remotePath, user, targetContext)
-                                .execute(client, getStorageManager())
+        TestCase.assertTrue(new CreateFolderOperation(remotePath, user, targetContext, getStorageManager())
+                                .execute(client)
                                 .isSuccess());
 
         return getStorageManager().getFileByDecryptedRemotePath(remotePath);
@@ -355,17 +355,18 @@ public abstract class AbstractIT {
                                                                                 targetContext.getContentResolver());
 
         UploadFileOperation newUpload = new UploadFileOperation(
-                uploadsStorageManager,
-                connectivityServiceMock,
-                powerManagementServiceMock,
-                user,
-                null,
-                ocUpload,
-                NameCollisionPolicy.DEFAULT,
-                FileUploader.LOCAL_BEHAVIOUR_COPY,
-                targetContext,
-                false,
-                false
+            uploadsStorageManager,
+            connectivityServiceMock,
+            powerManagementServiceMock,
+            user,
+            null,
+            ocUpload,
+            NameCollisionPolicy.DEFAULT,
+            FileUploader.LOCAL_BEHAVIOUR_COPY,
+            targetContext,
+            false,
+            false,
+            getStorageManager()
         );
         newUpload.addRenameUploadListener(() -> {
             // dummy
@@ -373,7 +374,7 @@ public abstract class AbstractIT {
 
         newUpload.setRemoteFolderToBeCreated();
 
-        RemoteOperationResult result = newUpload.execute(client, getStorageManager());
+        RemoteOperationResult result = newUpload.execute(client);
         assertTrue(result.getLogMessage(), result.isSuccess());
     }
 

+ 13 - 12
src/androidTest/java/com/owncloud/android/AbstractOnServerIT.java

@@ -203,17 +203,18 @@ public abstract class AbstractOnServerIT extends AbstractIT {
                                                                                 targetContext.getContentResolver());
 
         UploadFileOperation newUpload = new UploadFileOperation(
-                uploadsStorageManager,
-                connectivityServiceMock,
-                powerManagementServiceMock,
-                user,
-                null,
-                ocUpload,
-                NameCollisionPolicy.DEFAULT,
-                localBehaviour,
-                targetContext,
-                false,
-                false
+            uploadsStorageManager,
+            connectivityServiceMock,
+            powerManagementServiceMock,
+            user,
+            null,
+            ocUpload,
+            NameCollisionPolicy.DEFAULT,
+            localBehaviour,
+            targetContext,
+            false,
+            false,
+            getStorageManager()
         );
         newUpload.addRenameUploadListener(() -> {
             // dummy
@@ -221,7 +222,7 @@ public abstract class AbstractOnServerIT extends AbstractIT {
 
         newUpload.setRemoteFolderToBeCreated();
 
-        RemoteOperationResult result = newUpload.execute(client, getStorageManager());
+        RemoteOperationResult result = newUpload.execute(client);
         assertTrue(result.getLogMessage(), result.isSuccess());
 
         OCFile parentFolder = getStorageManager()

+ 3 - 2
src/androidTest/java/com/owncloud/android/DownloadIT.java

@@ -65,8 +65,9 @@ public class DownloadIT extends AbstractOnServerIT {
                                     false,
                                     account,
                                     false,
-                                    targetContext)
-                .execute(client, getStorageManager());
+                                    targetContext,
+                                    getStorageManager())
+                .execute(client);
         }
     }
 

+ 8 - 7
src/androidTest/java/com/owncloud/android/FileIT.java

@@ -27,8 +27,8 @@ public class FileIT extends AbstractOnServerIT {
         // folder does not exist yet
         assertNull(getStorageManager().getFileByPath(path));
 
-        SyncOperation syncOp = new CreateFolderOperation(path, user, targetContext);
-        RemoteOperationResult result = syncOp.execute(client, getStorageManager());
+        SyncOperation syncOp = new CreateFolderOperation(path, user, targetContext, getStorageManager());
+        RemoteOperationResult result = syncOp.execute(client);
 
         assertTrue(result.toString(), result.isSuccess());
 
@@ -37,7 +37,7 @@ public class FileIT extends AbstractOnServerIT {
         assertTrue(file.isFolder());
 
         // cleanup
-        new RemoveFileOperation(file, false, account, false, targetContext).execute(client, getStorageManager());
+        new RemoveFileOperation(file, false, account, false, targetContext, getStorageManager()).execute(client);
     }
 
     @Test
@@ -46,8 +46,8 @@ public class FileIT extends AbstractOnServerIT {
         // folder does not exist yet
         assertNull(getStorageManager().getFileByPath(path));
 
-        SyncOperation syncOp = new CreateFolderOperation(path, user, targetContext);
-        RemoteOperationResult result = syncOp.execute(client, getStorageManager());
+        SyncOperation syncOp = new CreateFolderOperation(path, user, targetContext, getStorageManager());
+        RemoteOperationResult result = syncOp.execute(client);
         assertTrue(result.toString(), result.isSuccess());
 
         // folder exists
@@ -59,7 +59,8 @@ public class FileIT extends AbstractOnServerIT {
                                 false,
                                 account,
                                 false,
-                                targetContext)
-            .execute(client, getStorageManager());
+                                targetContext,
+                                getStorageManager())
+            .execute(client);
     }
 }

+ 2 - 2
src/androidTest/java/com/owncloud/android/ScreenshotsIT.java

@@ -73,8 +73,8 @@ public class ScreenshotsIT extends AbstractOnServerIT {
 
         // folder does not exist yet
         if (getStorageManager().getFileByEncryptedRemotePath(path) == null) {
-            SyncOperation syncOp = new CreateFolderOperation(path, user, targetContext);
-            RemoteOperationResult result = syncOp.execute(client, getStorageManager());
+            SyncOperation syncOp = new CreateFolderOperation(path, user, targetContext, getStorageManager());
+            RemoteOperationResult result = syncOp.execute(client);
 
             assertTrue(result.isSuccess());
         }

+ 71 - 64
src/androidTest/java/com/owncloud/android/UploadIT.java

@@ -114,8 +114,9 @@ public class UploadIT extends AbstractOnServerIT {
                                     false,
                                     account,
                                     false,
-                                    targetContext)
-                .execute(client, getStorageManager());
+                                    targetContext,
+                                    getStorageManager())
+                .execute(client);
         }
     }
 
@@ -224,24 +225,25 @@ public class UploadIT extends AbstractOnServerIT {
         ocUpload.setWhileChargingOnly(true);
 
         UploadFileOperation newUpload = new UploadFileOperation(
-                uploadsStorageManager,
-                connectivityServiceMock,
-                powerManagementServiceMock,
-                user,
-                null,
-                ocUpload,
-                NameCollisionPolicy.DEFAULT,
-                FileUploader.LOCAL_BEHAVIOUR_COPY,
-                targetContext,
-                false,
-                true
+            uploadsStorageManager,
+            connectivityServiceMock,
+            powerManagementServiceMock,
+            user,
+            null,
+            ocUpload,
+            NameCollisionPolicy.DEFAULT,
+            FileUploader.LOCAL_BEHAVIOUR_COPY,
+            targetContext,
+            false,
+            true,
+            getStorageManager()
         );
         newUpload.setRemoteFolderToBeCreated();
         newUpload.addRenameUploadListener(() -> {
             // dummy
         });
 
-        RemoteOperationResult result = newUpload.execute(client, getStorageManager());
+        RemoteOperationResult result = newUpload.execute(client);
         assertFalse(result.toString(), result.isSuccess());
         assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_CHARGING, result.getCode());
     }
@@ -271,24 +273,25 @@ public class UploadIT extends AbstractOnServerIT {
         ocUpload.setWhileChargingOnly(true);
 
         UploadFileOperation newUpload = new UploadFileOperation(
-                uploadsStorageManager,
-                connectivityServiceMock,
-                powerManagementServiceMock,
-                user,
-                null,
-                ocUpload,
-                NameCollisionPolicy.DEFAULT,
-                FileUploader.LOCAL_BEHAVIOUR_COPY,
-                targetContext,
-                false,
-                true
+            uploadsStorageManager,
+            connectivityServiceMock,
+            powerManagementServiceMock,
+            user,
+            null,
+            ocUpload,
+            NameCollisionPolicy.DEFAULT,
+            FileUploader.LOCAL_BEHAVIOUR_COPY,
+            targetContext,
+            false,
+            true,
+            getStorageManager()
         );
         newUpload.setRemoteFolderToBeCreated();
         newUpload.addRenameUploadListener(() -> {
             // dummy
         });
 
-        RemoteOperationResult result = newUpload.execute(client, getStorageManager());
+        RemoteOperationResult result = newUpload.execute(client);
         assertTrue(result.toString(), result.isSuccess());
     }
 
@@ -310,24 +313,25 @@ public class UploadIT extends AbstractOnServerIT {
         ocUpload.setUseWifiOnly(true);
 
         UploadFileOperation newUpload = new UploadFileOperation(
-                uploadsStorageManager,
-                connectivityServiceMock,
-                powerManagementServiceMock,
-                user,
-                null,
-                ocUpload,
-                NameCollisionPolicy.DEFAULT,
-                FileUploader.LOCAL_BEHAVIOUR_COPY,
-                targetContext,
-                true,
-                false
+            uploadsStorageManager,
+            connectivityServiceMock,
+            powerManagementServiceMock,
+            user,
+            null,
+            ocUpload,
+            NameCollisionPolicy.DEFAULT,
+            FileUploader.LOCAL_BEHAVIOUR_COPY,
+            targetContext,
+            true,
+            false,
+            getStorageManager()
         );
         newUpload.setRemoteFolderToBeCreated();
         newUpload.addRenameUploadListener(() -> {
             // dummy
         });
 
-        RemoteOperationResult result = newUpload.execute(client, getStorageManager());
+        RemoteOperationResult result = newUpload.execute(client);
         assertFalse(result.toString(), result.isSuccess());
         assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI, result.getCode());
     }
@@ -339,24 +343,25 @@ public class UploadIT extends AbstractOnServerIT {
         ocUpload.setWhileChargingOnly(true);
 
         UploadFileOperation newUpload = new UploadFileOperation(
-                uploadsStorageManager,
-                connectivityServiceMock,
-                powerManagementServiceMock,
-                user,
-                null,
-                ocUpload,
-                NameCollisionPolicy.DEFAULT,
-                FileUploader.LOCAL_BEHAVIOUR_COPY,
-                targetContext,
-                true,
-                false
+            uploadsStorageManager,
+            connectivityServiceMock,
+            powerManagementServiceMock,
+            user,
+            null,
+            ocUpload,
+            NameCollisionPolicy.DEFAULT,
+            FileUploader.LOCAL_BEHAVIOUR_COPY,
+            targetContext,
+            true,
+            false,
+            getStorageManager()
         );
         newUpload.setRemoteFolderToBeCreated();
         newUpload.addRenameUploadListener(() -> {
             // dummy
         });
 
-        RemoteOperationResult result = newUpload.execute(client, getStorageManager());
+        RemoteOperationResult result = newUpload.execute(client);
         assertTrue(result.toString(), result.isSuccess());
 
         // cleanup
@@ -364,8 +369,9 @@ public class UploadIT extends AbstractOnServerIT {
                                 false,
                                 account,
                                 false,
-                                targetContext)
-            .execute(client, getStorageManager());
+                                targetContext,
+                                getStorageManager())
+            .execute(client);
     }
 
     @Test
@@ -387,24 +393,25 @@ public class UploadIT extends AbstractOnServerIT {
         ocUpload.setUseWifiOnly(true);
 
         UploadFileOperation newUpload = new UploadFileOperation(
-                uploadsStorageManager,
-                connectivityServiceMock,
-                powerManagementServiceMock,
-                user,
-                null,
-                ocUpload,
-                NameCollisionPolicy.DEFAULT,
-                FileUploader.LOCAL_BEHAVIOUR_COPY,
-                targetContext,
-                true,
-                false
+            uploadsStorageManager,
+            connectivityServiceMock,
+            powerManagementServiceMock,
+            user,
+            null,
+            ocUpload,
+            NameCollisionPolicy.DEFAULT,
+            FileUploader.LOCAL_BEHAVIOUR_COPY,
+            targetContext,
+            true,
+            false,
+            getStorageManager()
         );
         newUpload.setRemoteFolderToBeCreated();
         newUpload.addRenameUploadListener(() -> {
             // dummy
         });
 
-        RemoteOperationResult result = newUpload.execute(client, getStorageManager());
+        RemoteOperationResult result = newUpload.execute(client);
         assertFalse(result.toString(), result.isSuccess());
         assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI, result.getCode());
     }

+ 22 - 16
src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt

@@ -156,7 +156,7 @@ class FileUploaderIT : AbstractOnServerIT() {
         assertEquals(file.length(), (result.data[0] as RemoteFile).length)
 
         val ocFile2 = OCFile("/testFile.txt")
-        ocFile2.setStoragePath(getDummyFile("/empty.txt").absolutePath)
+        ocFile2.storagePath = getDummyFile("/empty.txt").absolutePath
 
         FileUploader.uploadUpdateFile(
             targetContext,
@@ -196,10 +196,11 @@ class FileUploaderIT : AbstractOnServerIT() {
                 FileUploader.LOCAL_BEHAVIOUR_COPY,
                 targetContext,
                 false,
-                false
+                false,
+                storageManager
             )
                 .setRemoteFolderToBeCreated()
-                .execute(client, storageManager)
+                .execute(client)
                 .isSuccess
         )
 
@@ -223,12 +224,13 @@ class FileUploaderIT : AbstractOnServerIT() {
                 FileUploader.LOCAL_BEHAVIOUR_COPY,
                 targetContext,
                 false,
-                false
+                false,
+                storageManager
             )
                 .addRenameUploadListener {
                     renameListenerWasTriggered = true
                 }
-                .execute(client, storageManager)
+                .execute(client)
                 .isSuccess
         )
 
@@ -273,7 +275,7 @@ class FileUploaderIT : AbstractOnServerIT() {
         assertEquals(file.length(), (result.data[0] as RemoteFile).length)
 
         val ocFile2 = OCFile("/testFile.txt")
-        ocFile2.setStoragePath(getDummyFile("/empty.txt").absolutePath)
+        ocFile2.storagePath = getDummyFile("/empty.txt").absolutePath
 
         FileUploader.uploadUpdateFile(
             targetContext,
@@ -316,10 +318,11 @@ class FileUploaderIT : AbstractOnServerIT() {
                 FileUploader.LOCAL_BEHAVIOUR_COPY,
                 targetContext,
                 false,
-                false
+                false,
+                storageManager
             )
                 .setRemoteFolderToBeCreated()
-                .execute(client, storageManager)
+                .execute(client)
                 .isSuccess
         )
 
@@ -342,9 +345,10 @@ class FileUploaderIT : AbstractOnServerIT() {
                 FileUploader.LOCAL_BEHAVIOUR_COPY,
                 targetContext,
                 false,
-                false
+                false,
+                storageManager
             )
-                .execute(client, storageManager).isSuccess
+                .execute(client).isSuccess
         )
 
         val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
@@ -382,7 +386,7 @@ class FileUploaderIT : AbstractOnServerIT() {
         assertEquals(file.length(), (result.data[0] as RemoteFile).length)
 
         val ocFile2 = OCFile("/testFile.txt")
-        ocFile2.setStoragePath(getDummyFile("/empty.txt").absolutePath)
+        ocFile2.storagePath = getDummyFile("/empty.txt").absolutePath
 
         FileUploader.uploadUpdateFile(
             targetContext,
@@ -420,10 +424,11 @@ class FileUploaderIT : AbstractOnServerIT() {
                 FileUploader.LOCAL_BEHAVIOUR_COPY,
                 targetContext,
                 false,
-                false
+                false,
+                storageManager
             )
                 .setRemoteFolderToBeCreated()
-                .execute(client, storageManager)
+                .execute(client)
                 .isSuccess
         )
 
@@ -445,9 +450,10 @@ class FileUploaderIT : AbstractOnServerIT() {
             FileUploader.LOCAL_BEHAVIOUR_COPY,
             targetContext,
             false,
-            false
+            false,
+            storageManager
         )
-            .execute(client, storageManager)
+            .execute(client)
 
         assertFalse(uploadResult.isSuccess)
         assertTrue(uploadResult.exception is OperationCancelledException)
@@ -487,7 +493,7 @@ class FileUploaderIT : AbstractOnServerIT() {
         assertEquals(file.length(), (result.data[0] as RemoteFile).length)
 
         val ocFile2 = OCFile("/testFile.txt")
-        ocFile2.setStoragePath(getDummyFile("/empty.txt").absolutePath)
+        ocFile2.storagePath = getDummyFile("/empty.txt").absolutePath
 
         FileUploader.uploadUpdateFile(
             targetContext,

+ 13 - 9
src/androidTest/java/com/owncloud/android/operations/RemoveFileOperationIT.java

@@ -38,7 +38,7 @@ public class RemoveFileOperationIT extends AbstractOnServerIT {
     public void deleteFolder() {
         String parent = "/test/";
         String path = parent + "folder1/";
-        assertTrue(new CreateFolderOperation(path, user, targetContext).execute(client, getStorageManager())
+        assertTrue(new CreateFolderOperation(path, user, targetContext, getStorageManager()).execute(client)
                        .isSuccess());
 
         OCFile folder = getStorageManager().getFileByPath(path);
@@ -49,8 +49,9 @@ public class RemoveFileOperationIT extends AbstractOnServerIT {
                                            false,
                                            account,
                                            false,
-                                           targetContext)
-                       .execute(client, getStorageManager())
+                                           targetContext,
+                                           getStorageManager())
+                       .execute(client)
                        .isSuccess());
 
         OCFile parentFolder = getStorageManager().getFileByPath(parent);
@@ -60,8 +61,9 @@ public class RemoveFileOperationIT extends AbstractOnServerIT {
                                            false,
                                            account,
                                            false,
-                                           targetContext)
-                       .execute(client, getStorageManager())
+                                           targetContext,
+                                           getStorageManager())
+                       .execute(client)
                        .isSuccess());
     }
 
@@ -81,8 +83,9 @@ public class RemoveFileOperationIT extends AbstractOnServerIT {
                                            false,
                                            account,
                                            false,
-                                           targetContext)
-                       .execute(client, getStorageManager())
+                                           targetContext,
+                                           getStorageManager())
+                       .execute(client)
                        .isSuccess());
 
         OCFile parentFolder = getStorageManager().getFileByPath(parent);
@@ -92,8 +95,9 @@ public class RemoveFileOperationIT extends AbstractOnServerIT {
                                            false,
                                            account,
                                            false,
-                                           targetContext)
-                       .execute(client, getStorageManager())
+                                           targetContext,
+                                           getStorageManager())
+                       .execute(client)
                        .isSuccess());
     }
 }

+ 10 - 2
src/androidTest/java/com/owncloud/android/util/ErrorMessageAdapterIT.java

@@ -22,9 +22,11 @@
 package com.owncloud.android.util;
 
 import android.accounts.Account;
+import android.content.Context;
 import android.content.res.Resources;
 
 import com.owncloud.android.MainApp;
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.operations.RemoveFileOperation;
@@ -48,12 +50,18 @@ public class ErrorMessageAdapterIT {
     public void getErrorCauseMessageForForbiddenRemoval() {
         Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
         Account account = new Account("name", ACCOUNT_TYPE);
+        Context context = MainApp.getAppContext();
 
         String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(
             new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN),
-            new RemoveFileOperation(new OCFile(PATH_TO_DELETE), false, account, false, MainApp.getAppContext()),
+            new RemoveFileOperation(new OCFile(PATH_TO_DELETE),
+                                    false,
+                                    account,
+                                    false,
+                                    context,
+                                    new FileDataStorageManager(account, context.getContentResolver())),
             resources
-        );
+                                                                      );
 
         assertEquals(EXPECTED_ERROR_MESSAGE, errorMessage);
     }

+ 3 - 2
src/main/java/com/nextcloud/client/files/downloader/UploadTask.kt

@@ -86,11 +86,12 @@ class UploadTask(
             applicationContext,
             upload.isUseWifiOnly,
             upload.isWhileChargingOnly,
-            false
+            false,
+            fileDataStorageManager
         )
         val client = clientProvider()
         uploadsStorageManager.updateDatabaseUploadStart(op)
-        val result = op.execute(client, fileDataStorageManager)
+        val result = op.execute(client)
         uploadsStorageManager.updateDatabaseUploadResult(result, op)
         return Result(file, result.isSuccess)
     }

+ 3 - 2
src/main/java/com/nextcloud/client/jobs/OfflineSyncWork.kt

@@ -113,9 +113,10 @@ class OfflineSyncWork constructor(
                     ocFile.remotePath,
                     user,
                     true,
-                    context
+                    context,
+                    storageManager
                 )
-                synchronizeFileOperation.execute(storageManager, context)
+                synchronizeFileOperation.execute(context)
             }
         }
         // recursive into folder

+ 5 - 3
src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -490,7 +490,8 @@ public class FileUploader extends Service
             this,
             onWifiOnly,
             whileChargingOnly,
-            disableRetries
+            disableRetries,
+            new FileDataStorageManager(user.toPlatformAccount(), getContentResolver())
         );
         newUpload.setCreatedBy(createdBy);
         if (isCreateRemoteFolder) {
@@ -539,7 +540,8 @@ public class FileUploader extends Service
             this,
             onWifiOnly,
             whileChargingOnly,
-            true
+            true,
+            new FileDataStorageManager(user.toPlatformAccount(), getContentResolver())
         );
 
         newUpload.addDataTransferProgressListener(this);
@@ -639,7 +641,7 @@ public class FileUploader extends Service
 //                    uploadResult = uploadEncryptedFileOperation.execute(mUploadClient, mStorageManager);
 //                } else {
                 /// perform the regular upload
-                uploadResult = mCurrentUpload.execute(mUploadClient, mStorageManager);
+                uploadResult = mCurrentUpload.execute(mUploadClient);
 //                }
             } catch (Exception e) {
                 Log_OC.e(TAG, "Error uploading", e);

+ 4 - 2
src/main/java/com/owncloud/android/operations/CheckCurrentCredentialsOperation.java

@@ -21,6 +21,7 @@
 package com.owncloud.android.operations;
 
 import com.nextcloud.client.account.User;
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
@@ -37,13 +38,14 @@ public class CheckCurrentCredentialsOperation extends SyncOperation {
 
     private final User user;
 
-    public CheckCurrentCredentialsOperation(User user) {
+    public CheckCurrentCredentialsOperation(User user, FileDataStorageManager storageManager) {
+        super(storageManager);
         this.user = user;
     }
 
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
-        RemoteOperationResult result = null;
+        RemoteOperationResult result;
         boolean validAccount = user.nameEquals(getStorageManager().getAccount().name);
         if (!validAccount) {
             result = new RemoteOperationResult(new IllegalStateException(

+ 4 - 4
src/main/java/com/owncloud/android/operations/CommentFileOperation.java

@@ -22,19 +22,19 @@
 package com.owncloud.android.operations;
 
 import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.comments.CommentFileRemoteOperation;
-import com.owncloud.android.operations.common.SyncOperation;
 
 
 /**
  * Comment file
  */
-public class CommentFileOperation extends SyncOperation {
+public class CommentFileOperation extends RemoteOperation {
 
-    private String message;
-    private String fileId;
+    private final String message;
+    private final String fileId;
 
     /**
      * Constructor

+ 5 - 2
src/main/java/com/owncloud/android/operations/CopyFileOperation.java

@@ -16,6 +16,7 @@
 
 package com.owncloud.android.operations;
 
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -31,7 +32,7 @@ import com.owncloud.android.operations.common.SyncOperation;
  */
 public class CopyFileOperation extends SyncOperation {
 
-    private String srcPath;
+    private final String srcPath;
     private String targetParentPath;
 
     /**
@@ -40,7 +41,9 @@ public class CopyFileOperation extends SyncOperation {
      * @param srcPath          Remote path of the {@link OCFile} to move.
      * @param targetParentPath Path to the folder where the file will be copied into.
      */
-    public CopyFileOperation(String srcPath, String targetParentPath) {
+    public CopyFileOperation(String srcPath, String targetParentPath, FileDataStorageManager storageManager) {
+        super(storageManager);
+
         this.srcPath = srcPath;
         this.targetParentPath = targetParentPath;
         if (!this.targetParentPath.endsWith(OCFile.PATH_SEPARATOR)) {

+ 4 - 1
src/main/java/com/owncloud/android/operations/CreateFolderOperation.java

@@ -28,6 +28,7 @@ import com.nextcloud.client.account.User;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.DecryptedFolderMetadata;
 import com.owncloud.android.datamodel.EncryptedFolderMetadata;
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
@@ -67,7 +68,9 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
     /**
      * Constructor
      */
-    public CreateFolderOperation(String remotePath, User user, Context context) {
+    public CreateFolderOperation(String remotePath, User user, Context context, FileDataStorageManager storageManager) {
+        super(storageManager);
+
         this.remotePath = remotePath;
         this.user = user;
         this.context = context;

+ 4 - 1
src/main/java/com/owncloud/android/operations/CreateShareViaLinkOperation.java

@@ -21,6 +21,7 @@
 
 package com.owncloud.android.operations;
 
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -40,7 +41,9 @@ public class CreateShareViaLinkOperation extends SyncOperation {
     private String path;
     private String password;
 
-    public CreateShareViaLinkOperation(String path, String password) {
+    public CreateShareViaLinkOperation(String path, String password, FileDataStorageManager storageManager) {
+        super(storageManager);
+
         this.path = path;
         this.password = password;
     }

+ 14 - 7
src/main/java/com/owncloud/android/operations/CreateShareWithShareeOperation.java

@@ -21,6 +21,7 @@
 
 package com.owncloud.android.operations;
 
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -54,14 +55,20 @@ public class CreateShareWithShareeOperation extends SyncOperation {
     /**
      * Constructor.
      *
-     * @param path          Full path of the file/folder being shared.
-     * @param shareeName    User or group name of the target sharee.
-     * @param shareType     Type of share determines type of sharee; {@link ShareType#USER} and {@link ShareType#GROUP}
-     *                      are the only valid values for the moment.
-     * @param permissions   Share permissions key as detailed in
-     *                      https://doc.owncloud.org/server/8.2/developer_manual/core/ocs-share-api.html .
+     * @param path        Full path of the file/folder being shared.
+     * @param shareeName  User or group name of the target sharee.
+     * @param shareType   Type of share determines type of sharee; {@link ShareType#USER} and {@link ShareType#GROUP}
+     *                    are the only valid values for the moment.
+     * @param permissions Share permissions key as detailed in https://doc.owncloud.org/server/8.2/developer_manual/core/ocs-share-api.html
+     *                    .
      */
-    public CreateShareWithShareeOperation(String path, String shareeName, ShareType shareType, int permissions) {
+    public CreateShareWithShareeOperation(String path,
+                                          String shareeName,
+                                          ShareType shareType,
+                                          int permissions,
+                                          FileDataStorageManager storageManager) {
+        super(storageManager);
+
         if (!supportedShareTypes.contains(shareType)) {
             throw new IllegalArgumentException("Illegal share type " + shareType);
         }

+ 4 - 0
src/main/java/com/owncloud/android/operations/GetCapabilitiesOperation.java

@@ -31,6 +31,10 @@ import com.owncloud.android.operations.common.SyncOperation;
  */
 public class GetCapabilitiesOperation extends SyncOperation {
 
+    public GetCapabilitiesOperation(FileDataStorageManager storageManager) {
+        super(storageManager);
+    }
+
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
         final FileDataStorageManager storageManager = getStorageManager();

+ 25 - 18
src/main/java/com/owncloud/android/operations/GetSharesForFileOperation.java

@@ -1,4 +1,4 @@
-/**
+/*
  *   ownCloud Android client application
  *
  *   @author masensio
@@ -21,6 +21,7 @@
 
 package com.owncloud.android.operations;
 
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
@@ -37,37 +38,43 @@ public class GetSharesForFileOperation extends SyncOperation {
 
     private static final String TAG = GetSharesForFileOperation.class.getSimpleName();
 
-    private String mPath;
-    private boolean mReshares;
-    private boolean mSubfiles;
+    private final String path;
+    private final boolean reshares;
+    private final boolean subfiles;
 
     /**
      * Constructor
      *
-     * @param path      Path to file or folder
-     * @param reshares  If set to false (default), only shares from the current user are returned
-     *                  If set to true, all shares from the given file are returned
-     * @param subfiles  If set to false (default), lists only the folder being shared
-     *                  If set to true, all shared files within the folder are returned.
+     * @param path     Path to file or folder
+     * @param reshares If set to false (default), only shares from the current user are returned If set to true, all
+     *                 shares from the given file are returned
+     * @param subfiles If set to false (default), lists only the folder being shared If set to true, all shared files
+     *                 within the folder are returned.
      */
-    public GetSharesForFileOperation(String path, boolean reshares, boolean subfiles) {
-        mPath = path;
-        mReshares = reshares;
-        mSubfiles = subfiles;
+    public GetSharesForFileOperation(String path,
+                                     boolean reshares,
+                                     boolean subfiles,
+                                     FileDataStorageManager storageManager) {
+        super(storageManager);
+
+        this.path = path;
+        this.reshares = reshares;
+        this.subfiles = subfiles;
     }
 
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
-        GetSharesForFileRemoteOperation operation = new GetSharesForFileRemoteOperation(mPath,
-                                                                                        mReshares, mSubfiles);
+        GetSharesForFileRemoteOperation operation = new GetSharesForFileRemoteOperation(path,
+                                                                                        reshares,
+                                                                                        subfiles);
         RemoteOperationResult result = operation.execute(client);
 
         if (result.isSuccess()) {
 
             // Update DB with the response
-            Log_OC.d(TAG, "File = " + mPath + " Share list size  " + result.getData().size());
+            Log_OC.d(TAG, "File = " + path + " Share list size  " + result.getData().size());
             ArrayList<OCShare> shares = new ArrayList<OCShare>();
-            for(Object obj: result.getData()) {
+            for (Object obj : result.getData()) {
                 shares.add((OCShare) obj);
             }
 
@@ -75,7 +82,7 @@ public class GetSharesForFileOperation extends SyncOperation {
 
         } else if (result.getCode() == RemoteOperationResult.ResultCode.SHARE_NOT_FOUND) {
             // no share on the file - remove local shares
-            getStorageManager().removeSharesForFile(mPath);
+            getStorageManager().removeSharesForFile(path);
 
         }
 

+ 6 - 1
src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java

@@ -24,6 +24,7 @@ import android.accounts.AccountManager;
 
 import com.nextcloud.common.NextcloudClient;
 import com.owncloud.android.MainApp;
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.lib.common.UserInfo;
 import com.owncloud.android.lib.common.accounts.AccountUtils;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -32,11 +33,15 @@ import com.owncloud.android.operations.common.SyncOperation;
 
 /**
  * Get and save user's profile from the server.
- *
+ * <p>
  * Currently only retrieves the display name.
  */
 public class GetUserProfileOperation extends SyncOperation {
 
+    public GetUserProfileOperation(FileDataStorageManager storageManager) {
+        super(storageManager);
+    }
+
     /**
      * Performs the operation.
      *

+ 7 - 4
src/main/java/com/owncloud/android/operations/MoveFileOperation.java

@@ -19,6 +19,7 @@
 
 package com.owncloud.android.operations;
 
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -32,16 +33,18 @@ import com.owncloud.android.operations.common.SyncOperation;
  */
 public class MoveFileOperation extends SyncOperation {
 
-    private String srcPath;
+    private final String srcPath;
     private String targetParentPath;
 
     /**
      * Constructor
      *
-     * @param srcPath           Remote path of the {@link OCFile} to move.
-     * @param targetParentPath  Path to the folder where the file will be moved into.
+     * @param srcPath          Remote path of the {@link OCFile} to move.
+     * @param targetParentPath Path to the folder where the file will be moved into.
      */
-    public MoveFileOperation(String srcPath, String targetParentPath) {
+    public MoveFileOperation(String srcPath, String targetParentPath, FileDataStorageManager storageManager) {
+        super(storageManager);
+
         this.srcPath = srcPath;
         this.targetParentPath = targetParentPath;
         if (!this.targetParentPath.endsWith(OCFile.PATH_SEPARATOR)) {

+ 3 - 5
src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java

@@ -284,8 +284,7 @@ public class RefreshFolderOperation extends RemoteOperation {
         try {
             NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(mAccount, mContext);
 
-            RemoteOperationResult<UserInfo> result = new GetUserProfileOperation().execute(nextcloudClient,
-                                                                                           mStorageManager);
+            RemoteOperationResult<UserInfo> result = new GetUserProfileOperation(mStorageManager).execute(nextcloudClient);
             if (!result.isSuccess()) {
                 Log_OC.w(TAG, "Couldn't update user profile from server");
             } else {
@@ -301,8 +300,7 @@ public class RefreshFolderOperation extends RemoteOperation {
         String oldDirectEditingEtag = arbitraryDataProvider.getValue(mAccount,
                                                                      ArbitraryDataProvider.DIRECT_EDITING_ETAG);
 
-        GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation();
-        RemoteOperationResult result = getCapabilities.execute(mStorageManager, mContext);
+        RemoteOperationResult result = new GetCapabilitiesOperation(mStorageManager).execute(mContext);
         if (result.isSuccess()) {
             String newDirectEditingEtag = mStorageManager.getCapability(mAccount.name).getDirectEditingEtag();
 
@@ -657,7 +655,7 @@ public class RefreshFolderOperation extends RemoteOperation {
     private void startContentSynchronizations(List<SynchronizeFileOperation> filesToSyncContents) {
         RemoteOperationResult contentsResult;
         for (SynchronizeFileOperation op : filesToSyncContents) {
-            contentsResult = op.execute(mStorageManager, mContext);   // async
+            contentsResult = op.execute(mContext);   // async
             if (!contentsResult.isSuccess()) {
                 if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
                     mConflictsFound++;

+ 10 - 6
src/main/java/com/owncloud/android/operations/RemoveFileOperation.java

@@ -25,6 +25,7 @@ package com.owncloud.android.operations;
 import android.accounts.Account;
 import android.content.Context;
 
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.lib.common.OwnCloudClient;
@@ -41,11 +42,11 @@ import com.owncloud.android.utils.MimeTypeUtil;
  */
 public class RemoveFileOperation extends SyncOperation {
 
-    private OCFile fileToRemove;
-    private boolean onlyLocalCopy;
-    private Account account;
-    private boolean inBackground;
-    private Context context;
+    private final OCFile fileToRemove;
+    private final boolean onlyLocalCopy;
+    private final Account account;
+    private final boolean inBackground;
+    private final Context context;
 
 
     /**
@@ -58,7 +59,10 @@ public class RemoveFileOperation extends SyncOperation {
                                boolean onlyLocalCopy,
                                Account account,
                                boolean inBackground,
-                               Context context) {
+                               Context context,
+                               FileDataStorageManager storageManager) {
+        super(storageManager);
+
         this.fileToRemove = fileToRemove;
         this.onlyLocalCopy = onlyLocalCopy;
         this.account = account;

+ 5 - 4
src/main/java/com/owncloud/android/operations/RenameFileOperation.java

@@ -52,11 +52,12 @@ public class RenameFileOperation extends SyncOperation {
     /**
      * Constructor
      *
-     * @param remotePath            RemotePath of the OCFile instance describing the remote file or
-     *                              folder to rename
-     * @param newName               New name to set as the name of file.
+     * @param remotePath RemotePath of the OCFile instance describing the remote file or folder to rename
+     * @param newName    New name to set as the name of file.
      */
-    public RenameFileOperation(String remotePath, String newName) {
+    public RenameFileOperation(String remotePath, String newName, FileDataStorageManager storageManager) {
+        super(storageManager);
+
         this.remotePath = remotePath;
         this.newName = newName;
     }

+ 24 - 18
src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java

@@ -26,6 +26,7 @@ import android.content.Intent;
 import android.text.TextUtils;
 
 import com.nextcloud.client.account.User;
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.files.services.FileDownloader;
 import com.owncloud.android.files.services.FileUploader;
@@ -77,10 +78,12 @@ public class SynchronizeFileOperation extends SyncOperation {
      * @param context          Android context; needed to start transfers.
      */
     public SynchronizeFileOperation(
-            String remotePath,
-            User user,
-            boolean syncFileContents,
-            Context context) {
+        String remotePath,
+        User user,
+        boolean syncFileContents,
+        Context context,
+        FileDataStorageManager storageManager) {
+        super(storageManager);
 
         mRemotePath = remotePath;
         mLocalFile = null;
@@ -112,11 +115,13 @@ public class SynchronizeFileOperation extends SyncOperation {
      * @param context          Android context; needed to start transfers.
      */
     public SynchronizeFileOperation(
-            OCFile localFile,
-            OCFile serverFile,
-            User user,
-            boolean syncFileContents,
-            Context context) {
+        OCFile localFile,
+        OCFile serverFile,
+        User user,
+        boolean syncFileContents,
+        Context context,
+        FileDataStorageManager storageManager) {
+        super(storageManager);
 
         mLocalFile = localFile;
         mServerFile = serverFile;
@@ -124,7 +129,7 @@ public class SynchronizeFileOperation extends SyncOperation {
             mRemotePath = mLocalFile.getRemotePath();
             if (mServerFile != null && !mServerFile.getRemotePath().equals(mRemotePath)) {
                 throw new IllegalArgumentException("serverFile and localFile do not correspond" +
-                        " to the same OC file");
+                                                       " to the same OC file");
             }
         } else if (mServerFile != null) {
             mRemotePath = mServerFile.getRemotePath();
@@ -162,14 +167,15 @@ public class SynchronizeFileOperation extends SyncOperation {
      * @param context          Android context; needed to start transfers.
      */
     public SynchronizeFileOperation(
-            OCFile localFile,
-            OCFile serverFile,
-            User user,
-            boolean syncFileContents,
-            boolean allowUploads,
-            Context context) {
-
-        this(localFile, serverFile, user, syncFileContents, context);
+        OCFile localFile,
+        OCFile serverFile,
+        User user,
+        boolean syncFileContents,
+        boolean allowUploads,
+        Context context,
+        FileDataStorageManager storageManager) {
+
+        this(localFile, serverFile, user, syncFileContents, context, storageManager);
         mAllowUploads = allowUploads;
     }
 

+ 25 - 17
src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -100,12 +100,18 @@ public class SynchronizeFolderOperation extends SyncOperation {
     /**
      * Creates a new instance of {@link SynchronizeFolderOperation}.
      *
-     * @param   context                 Application context.
-     * @param   remotePath              Path to synchronize.
-     * @param   user                    Nextcloud account where the folder is located.
-     * @param   currentSyncTime         Time stamp for the synchronization process in progress.
+     * @param context         Application context.
+     * @param remotePath      Path to synchronize.
+     * @param user            Nextcloud account where the folder is located.
+     * @param currentSyncTime Time stamp for the synchronization process in progress.
      */
-    public SynchronizeFolderOperation(Context context, String remotePath, User user, long currentSyncTime){
+    public SynchronizeFolderOperation(Context context,
+                                      String remotePath,
+                                      User user,
+                                      long currentSyncTime,
+                                      FileDataStorageManager storageManager) {
+        super(storageManager);
+
         mRemotePath = remotePath;
         mCurrentSyncTime = currentSyncTime;
         this.user = user;
@@ -383,12 +389,13 @@ public class SynchronizeFolderOperation extends SyncOperation {
         } else {
             /// prepare content synchronization for files (any file, not just favorites)
             SynchronizeFileOperation operation = new SynchronizeFileOperation(
-                    localFile,
-                    remoteFile,
-                    user,
-                    true,
-                    mContext
-                );
+                localFile,
+                remoteFile,
+                user,
+                true,
+                mContext,
+                getStorageManager()
+            );
             mFilesToSyncContents.add(operation);
         }
     }
@@ -415,11 +422,12 @@ public class SynchronizeFolderOperation extends SyncOperation {
                 } else {
                     /// this should result in direct upload of files that were locally modified
                     SynchronizeFileOperation operation = new SynchronizeFileOperation(
-                            child,
-                            child.getEtagInConflict() != null ? child : null,
-                            user,
-                            true,
-                            mContext
+                        child,
+                        child.getEtagInConflict() != null ? child : null,
+                        user,
+                        true,
+                        mContext,
+                        getStorageManager()
                     );
                     mFilesToSyncContents.add(operation);
 
@@ -471,7 +479,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
             if (mCancellationRequested.get()) {
                 throw new OperationCancelledException();
             }
-            contentsResult = op.execute(getStorageManager(), mContext);
+            contentsResult = op.execute(mContext);
             if (!contentsResult.isSuccess()) {
                 if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
                     mConflictsFound++;

+ 10 - 8
src/main/java/com/owncloud/android/operations/UnshareOperation.java

@@ -21,6 +21,7 @@
 
 package com.owncloud.android.operations;
 
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -35,19 +36,20 @@ import com.owncloud.android.operations.common.SyncOperation;
 import java.util.List;
 
 /**
- * Unshare file/folder
- * Save the data in Database
+ * Unshare file/folder Save the data in Database
  */
 public class UnshareOperation extends SyncOperation {
 
     private static final String TAG = UnshareOperation.class.getSimpleName();
     private static final int SINGLY_SHARED = 1;
 
-    private String mRemotePath;
-    private long shareId;
+    private final String remotePath;
+    private final long shareId;
 
-    public UnshareOperation(String remotePath, long shareId) {
-        mRemotePath = remotePath;
+    public UnshareOperation(String remotePath, long shareId, FileDataStorageManager storageManager) {
+        super(storageManager);
+
+        this.remotePath = remotePath;
         this.shareId = shareId;
     }
 
@@ -59,7 +61,7 @@ public class UnshareOperation extends SyncOperation {
         OCShare share = getStorageManager().getShareById(shareId);
 
         if (share != null) {
-            OCFile file = getStorageManager().getFileByEncryptedRemotePath(mRemotePath);
+            OCFile file = getStorageManager().getFileByEncryptedRemotePath(remotePath);
             RemoveShareRemoteOperation operation = new RemoveShareRemoteOperation(share.getRemoteId());
             result = operation.execute(client);
 
@@ -72,7 +74,7 @@ public class UnshareOperation extends SyncOperation {
                     || ShareType.FEDERATED.equals(share.getShareType())) {
                     // Check if it is the last share
                     List<OCShare> sharesWith = getStorageManager().
-                        getSharesWithForAFile(mRemotePath,
+                        getSharesWithForAFile(remotePath,
                                               getStorageManager().getAccount().name);
                     if (sharesWith.size() == SINGLY_SHARED) {
                         file.setSharedWithSharee(false);

+ 6 - 3
src/main/java/com/owncloud/android/operations/UpdateNoteForShareOperation.java

@@ -21,6 +21,7 @@
 
 package com.owncloud.android.operations;
 
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -35,10 +36,12 @@ import com.owncloud.android.operations.common.SyncOperation;
  */
 public class UpdateNoteForShareOperation extends SyncOperation {
 
-    private long shareId;
-    private String note;
+    private final long shareId;
+    private final String note;
+
+    public UpdateNoteForShareOperation(long shareId, String note, FileDataStorageManager storageManager) {
+        super(storageManager);
 
-    public UpdateNoteForShareOperation(long shareId, String note) {
         this.shareId = shareId;
         this.note = note;
     }

+ 1 - 1
src/main/java/com/owncloud/android/operations/UpdateOCVersionOperation.java

@@ -67,7 +67,7 @@ public class UpdateOCVersionOperation extends RemoteOperation {
         RemoteOperationResult result = null;
         GetMethod getMethod = null;
 
-        String webDav = client.getDavUri().toString();
+        String webDav = client.getFilesDavUri().toString();
 
         try {
             getMethod = new GetMethod(statUrl);

+ 6 - 7
src/main/java/com/owncloud/android/operations/UpdateSharePermissionsOperation.java

@@ -23,6 +23,7 @@ package com.owncloud.android.operations;
 
 import android.text.TextUtils;
 
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -38,7 +39,7 @@ import com.owncloud.android.operations.common.SyncOperation;
  */
 public class UpdateSharePermissionsOperation extends SyncOperation {
 
-    private long shareId;
+    private final long shareId;
     private int permissions;
     private long expirationDateInMillis;
     private String password;
@@ -49,7 +50,9 @@ public class UpdateSharePermissionsOperation extends SyncOperation {
      *
      * @param shareId Private {@link OCShare} to update. Mandatory argument
      */
-    public UpdateSharePermissionsOperation(long shareId) {
+    public UpdateSharePermissionsOperation(long shareId, FileDataStorageManager storageManager) {
+        super(storageManager);
+
         this.shareId = shareId;
         permissions = -1;
         expirationDateInMillis = 0L;
@@ -91,11 +94,7 @@ public class UpdateSharePermissionsOperation extends SyncOperation {
     private void updateData(OCShare share) {
         // Update DB with the response
         share.setPath(path);   // TODO - check if may be moved to UpdateRemoteShareOperation
-        if (path.endsWith(FileUtils.PATH_SEPARATOR)) {
-            share.setFolder(true);
-        } else {
-            share.setFolder(false);
-        }
+        share.setFolder(path.endsWith(FileUtils.PATH_SEPARATOR));
 
         share.setPasswordProtected(!TextUtils.isEmpty(password));
         getStorageManager().saveShare(share);

+ 5 - 2
src/main/java/com/owncloud/android/operations/UpdateShareViaLinkOperation.java

@@ -20,6 +20,7 @@
 
 package com.owncloud.android.operations;
 
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -36,10 +37,12 @@ public class UpdateShareViaLinkOperation extends SyncOperation {
     private String password;
     private Boolean hideFileDownload;
     private long expirationDateInMillis;
-    private long shareId;
+    private final long shareId;
     private String label;
 
-    public UpdateShareViaLinkOperation(long shareId) {
+    public UpdateShareViaLinkOperation(long shareId, FileDataStorageManager storageManager) {
+        super(storageManager);
+
         expirationDateInMillis = 0;
         this.shareId = shareId;
     }

+ 21 - 6
src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -182,9 +182,21 @@ public class UploadFileOperation extends SyncOperation {
                                int localBehaviour,
                                Context context,
                                boolean onWifiOnly,
-                               boolean whileChargingOnly) {
-        this(uploadsStorageManager, connectivityService, powerManagementService, user, file, upload,
-             nameCollisionPolicy, localBehaviour, context, onWifiOnly, whileChargingOnly, true);
+                               boolean whileChargingOnly,
+                               FileDataStorageManager storageManager) {
+        this(uploadsStorageManager,
+             connectivityService,
+             powerManagementService,
+             user,
+             file,
+             upload,
+             nameCollisionPolicy,
+             localBehaviour,
+             context,
+             onWifiOnly,
+             whileChargingOnly,
+             true,
+             storageManager);
     }
 
     public UploadFileOperation(UploadsStorageManager uploadsStorageManager,
@@ -198,7 +210,10 @@ public class UploadFileOperation extends SyncOperation {
                                Context context,
                                boolean onWifiOnly,
                                boolean whileChargingOnly,
-                               boolean disableRetries) {
+                               boolean disableRetries,
+                               FileDataStorageManager storageManager) {
+        super(storageManager);
+
         if (upload == null) {
             throw new IllegalArgumentException("Illegal NULL file in UploadFileOperation creation");
         }
@@ -1026,8 +1041,8 @@ public class UploadFileOperation extends SyncOperation {
         RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, false);
         RemoteOperationResult result = operation.execute(client);
         if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mRemoteFolderToBeCreated) {
-            SyncOperation syncOp = new CreateFolderOperation(pathToGrant, user, getContext());
-            result = syncOp.execute(client, getStorageManager());
+            SyncOperation syncOp = new CreateFolderOperation(pathToGrant, user, getContext(), getStorageManager());
+            result = syncOp.execute(client);
         }
         if (result.isSuccess()) {
             OCFile parentDir = getStorageManager().getFileByPath(pathToGrant);

+ 21 - 93
src/main/java/com/owncloud/android/operations/common/SyncOperation.java

@@ -39,123 +39,51 @@ import androidx.annotation.NonNull;
  * Provides methods to execute the operation both synchronously or asynchronously.
  */
 public abstract class SyncOperation extends RemoteOperation {
-    private FileDataStorageManager storageManager;
+    private final FileDataStorageManager storageManager;
 
-    /**
-     * Synchronously executes the operation on the received ownCloud account.
-     *
-     * Do not call this method from the main thread.
-     *
-     * This method should be used whenever an ownCloud account is available, instead of
-     * {@link #execute(OwnCloudClient, com.owncloud.android.datamodel.FileDataStorageManager)}.
-     *
-     * @param storageManager
-     * @param context   Android context for the component calling the method.
-     * @return          Result of the operation.
-     */
-    public RemoteOperationResult execute(FileDataStorageManager storageManager, Context context) {
-        if (storageManager == null) {
-            throw new IllegalArgumentException("Trying to execute a sync operation with a " +
-                    "NULL storage manager");
-        }
-        if (storageManager.getAccount() == null) {
-            throw new IllegalArgumentException("Trying to execute a sync operation with a " +
-                    "storage manager for a NULL account");
-        }
+    public SyncOperation(@NonNull FileDataStorageManager storageManager) {
         this.storageManager = storageManager;
-        return super.execute(this.storageManager.getAccount(), context);
     }
 
-
     /**
-	 * Synchronously executes the remote operation
-     *
+     * Synchronously executes the operation on the received ownCloud account.
+     * <p>
      * Do not call this method from the main thread.
+     * <p>
+     * This method should be used whenever an ownCloud account is available, instead of {@link
+     * #execute(OwnCloudClient)}.
      *
-	 * @param client	Client object to reach an ownCloud server during the execution of the o
-     *                  peration.
-     * @param storageManager
-	 * @return			Result of the operation.
+     * @param context Android context for the component calling the method.
+     * @return Result of the operation.
      */
-    public RemoteOperationResult execute(OwnCloudClient client,
-                                         FileDataStorageManager storageManager) {
-        if (storageManager == null) {
+    public RemoteOperationResult execute(Context context) {
+        if (storageManager.getAccount() == null) {
             throw new IllegalArgumentException("Trying to execute a sync operation with a " +
-                                                   "NULL storage manager");
+                                                   "storage manager for a NULL account");
         }
-        this.storageManager = storageManager;
-        return super.execute(client);
+        return super.execute(this.storageManager.getAccount(), context);
     }
 
-    public RemoteOperationResult execute(@NonNull NextcloudClient client, FileDataStorageManager storageManager) {
-        if (storageManager == null) {
-            throw new IllegalArgumentException("Trying to execute a sync operation with a NULL storage manager");
-        }
-        this.storageManager = storageManager;
-
+    public RemoteOperationResult execute(@NonNull NextcloudClient client) {
         return run(client);
     }
 
-
     /**
      * Asynchronously executes the remote operation
      *
-     * This method should be used whenever an ownCloud account is available, instead of
-     * {@link #execute(OwnCloudClient)}.
-     *
-     * @param account           ownCloud account in remote ownCloud server to reach during the
+     * @param client            Client object to reach an ownCloud server during the
      *                          execution of the operation.
-     * @param context           Android context for the component calling the method.
-     * @param listener          Listener to be notified about the execution of the operation.
-     * @param listenerHandler   Handler associated to the thread where the methods of the listener
-     *                          objects must be called.
-     * @return                  Thread were the remote operation is executed.
-     */
-	/*
-    public Thread execute(FileDataStorageManager storageManager,
-    Context context, OnRemoteOperationListener listener, Handler listenerHandler, Activity callerActivity) {
-        if (storageManager == null) {
-            throw new IllegalArgumentException("Trying to execute a sync operation
-             with a NULL storage manager");
-        }
-        if (storageManager.getAccount() == null) {
-            throw new IllegalArgumentException("Trying to execute a sync operation with a
-             storage manager for a NULL account");
-        }
-        storageManager = storageManager;
-        return super.execute(storageManager.getAccount(), context, listener, listenerHandler,
-         callerActivity);
-    }
-    */
-
-
-    /**
-	 * Asynchronously executes the remote operation
-     *
-	 * @param client			Client object to reach an ownCloud server during the
-     *                          execution of the operation.
-	 * @param listener			Listener to be notified about the execution of the operation.
-	 * @param listenerHandler	Handler associated to the thread where the methods of
+     * @param listener            Listener to be notified about the execution of the operation.
+     * @param listenerHandler    Handler associated to the thread where the methods of
      *                          the listener objects must be called.
-	 * @return					Thread were the remote operation is executed.
+     * @return Thread were the remote operation is executed.
      */
-    public Thread execute(OwnCloudClient client, FileDataStorageManager storageManager,
-                          OnRemoteOperationListener listener, Handler listenerHandler) {
-        if (storageManager == null) {
-            throw new IllegalArgumentException("Trying to execute a sync operation " +
-                                                   "with a NULL storage manager");
-        }
-        this.storageManager = storageManager;
+    public Thread execute(OwnCloudClient client,
+                          OnRemoteOperationListener listener,
+                          Handler listenerHandler) {
         return super.execute(client, listener, listenerHandler);
     }
 
-    @Override
-    public RemoteOperationResult execute(OwnCloudClient client) {
-        throw new IllegalArgumentException("Trying to execute a sync operation without storage provider! Please use " +
-                                               "execute(OwnCloudClient client, FileDataStorageManager storageManager)" +
-                                               " instead");
-    }
-
     public FileDataStorageManager getStorageManager() {
         return this.storageManager;
     }

+ 18 - 10
src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java

@@ -328,8 +328,10 @@ public class DocumentsStorageProvider extends DocumentsProvider {
 
         Document document = toDocument(documentId);
 
-        RemoteOperationResult result = new RenameFileOperation(document.getRemotePath(), displayName)
-            .execute(document.getClient(), document.getStorageManager());
+        RemoteOperationResult result = new RenameFileOperation(document.getRemotePath(),
+                                                               displayName,
+                                                               document.getStorageManager())
+            .execute(document.getClient());
 
         if (!result.isSuccess()) {
             Log_OC.e(TAG, result.toString());
@@ -352,8 +354,10 @@ public class DocumentsStorageProvider extends DocumentsProvider {
         FileDataStorageManager storageManager = document.getStorageManager();
         Document targetFolder = toDocument(targetParentDocumentId);
 
-        RemoteOperationResult result = new CopyFileOperation(document.getRemotePath(), targetFolder.getRemotePath())
-            .execute(document.getClient(), storageManager);
+        RemoteOperationResult result = new CopyFileOperation(document.getRemotePath(),
+                                                             targetFolder.getRemotePath(),
+                                                             document.getStorageManager())
+            .execute(document.getClient());
 
         if (!result.isSuccess()) {
             Log_OC.e(TAG, result.toString());
@@ -395,8 +399,10 @@ public class DocumentsStorageProvider extends DocumentsProvider {
         Document document = toDocument(sourceDocumentId);
         Document targetFolder = toDocument(targetParentDocumentId);
 
-        RemoteOperationResult result = new MoveFileOperation(document.getRemotePath(), targetFolder.getRemotePath())
-            .execute(document.getClient(), document.getStorageManager());
+        RemoteOperationResult result = new MoveFileOperation(document.getRemotePath(),
+                                                             targetFolder.getRemotePath(),
+                                                             document.getStorageManager())
+            .execute(document.getClient());
 
         if (!result.isSuccess()) {
             Log_OC.e(TAG, result.toString());
@@ -452,8 +458,9 @@ public class DocumentsStorageProvider extends DocumentsProvider {
 
         RemoteOperationResult result = new CreateFolderOperation(newDirPath,
                                                                  accountManager.getUser(),
-                                                                 context)
-            .execute(targetFolder.getClient(), storageManager);
+                                                                 context,
+                                                                 storageManager)
+            .execute(targetFolder.getClient());
 
         if (!result.isSuccess()) {
             Log_OC.e(TAG, result.toString());
@@ -568,8 +575,9 @@ public class DocumentsStorageProvider extends DocumentsProvider {
                                                                false,
                                                                document.getAccount(),
                                                                true,
-                                                               context)
-            .execute(document.getClient(), document.getStorageManager());
+                                                               context,
+                                                               document.getStorageManager())
+            .execute(document.getClient());
 
         if (!result.isSuccess()) {
             throw new FileNotFoundException("Failed to delete document with documentId " + documentId);

+ 35 - 37
src/main/java/com/owncloud/android/services/OperationsService.java

@@ -69,7 +69,6 @@ import com.owncloud.android.operations.UnshareOperation;
 import com.owncloud.android.operations.UpdateNoteForShareOperation;
 import com.owncloud.android.operations.UpdateSharePermissionsOperation;
 import com.owncloud.android.operations.UpdateShareViaLinkOperation;
-import com.owncloud.android.operations.common.SyncOperation;
 
 import java.io.IOException;
 import java.util.Iterator;
@@ -391,8 +390,6 @@ public class OperationsService extends Service {
         private RemoteOperation mCurrentOperation;
         private Target mLastTarget;
         private OwnCloudClient mOwnCloudClient;
-        private FileDataStorageManager mStorageManager;
-
 
         public ServiceHandler(Looper looper, OperationsService service) {
             super(looper);
@@ -428,31 +425,18 @@ public class OperationsService extends Service {
                     /// prepare client object to send the request to the ownCloud server
                     if (mLastTarget == null || !mLastTarget.equals(next.first)) {
                         mLastTarget = next.first;
+                        OwnCloudAccount ocAccount;
                         if (mLastTarget.mAccount != null) {
-                            OwnCloudAccount ocAccount = new OwnCloudAccount(mLastTarget.mAccount, mService);
-                            mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
-                                    getClientFor(ocAccount, mService);
-
-                            mStorageManager = new FileDataStorageManager(
-                                mLastTarget.mAccount,
-                                    mService.getContentResolver()
-                            );
+                            ocAccount = new OwnCloudAccount(mLastTarget.mAccount, mService);
                         } else {
-                            OwnCloudAccount ocAccount = new OwnCloudAccount(mLastTarget.mServerUrl, null);
-                            mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
-                                    getClientFor(ocAccount, mService);
-                            mStorageManager = null;
+                            ocAccount = new OwnCloudAccount(mLastTarget.mServerUrl, null);
                         }
+                        mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+                            getClientFor(ocAccount, mService);
                     }
 
                     /// perform the operation
-                    if (mCurrentOperation instanceof SyncOperation) {
-                        result = ((SyncOperation)mCurrentOperation).execute(mOwnCloudClient,
-                                mStorageManager);
-                    } else {
-                        result = mCurrentOperation.execute(mOwnCloudClient);
-                    }
-
+                    result = mCurrentOperation.execute(mOwnCloudClient);
                 } catch (AccountsException e) {
                     if (mLastTarget.mAccount == null) {
                         Log_OC.e(TAG, "Error while trying to get authorization for a NULL account",
@@ -523,12 +507,15 @@ public class OperationsService extends Service {
                 String newParentPath;
                 long shareId;
 
+                FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(account,
+                                                                                           getContentResolver());
+
                 switch (action) {
                     case ACTION_CREATE_SHARE_VIA_LINK:
                         remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                         password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
                         if (!TextUtils.isEmpty(remotePath)) {
-                            operation = new CreateShareViaLinkOperation(remotePath, password);
+                            operation = new CreateShareViaLinkOperation(remotePath, password, fileDataStorageManager);
                         }
                         break;
 
@@ -536,7 +523,8 @@ public class OperationsService extends Service {
                         shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
 
                         if (shareId > 0) {
-                            UpdateShareViaLinkOperation updateLinkOperation = new UpdateShareViaLinkOperation(shareId);
+                            UpdateShareViaLinkOperation updateLinkOperation =
+                                new UpdateShareViaLinkOperation(shareId, fileDataStorageManager);
 
                             password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
                             updateLinkOperation.setPassword(password);
@@ -564,7 +552,8 @@ public class OperationsService extends Service {
                         shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
 
                         if (shareId > 0) {
-                            UpdateSharePermissionsOperation updateShare = new UpdateSharePermissionsOperation(shareId);
+                            UpdateSharePermissionsOperation updateShare =
+                                new UpdateSharePermissionsOperation(shareId, fileDataStorageManager);
 
                             int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
                             updateShare.setPermissions(permissions);
@@ -585,7 +574,7 @@ public class OperationsService extends Service {
                         String note = operationIntent.getStringExtra(EXTRA_SHARE_NOTE);
 
                         if (shareId > 0) {
-                            operation = new UpdateNoteForShareOperation(shareId, note);
+                            operation = new UpdateNoteForShareOperation(shareId, note, fileDataStorageManager);
                         }
                         break;
 
@@ -595,8 +584,11 @@ public class OperationsService extends Service {
                         shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
                         int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
                         if (!TextUtils.isEmpty(remotePath)) {
-                            operation = new CreateShareWithShareeOperation(remotePath, shareeName, shareType,
-                                                                           permissions);
+                            operation = new CreateShareWithShareeOperation(remotePath,
+                                                                           shareeName,
+                                                                           shareType,
+                                                                           permissions,
+                                                                           fileDataStorageManager);
                         }
                         break;
 
@@ -605,7 +597,7 @@ public class OperationsService extends Service {
                         shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
 
                         if (shareId > 0) {
-                            operation = new UnshareOperation(remotePath, shareId);
+                            operation = new UnshareOperation(remotePath, shareId, fileDataStorageManager);
                         }
                         break;
 
@@ -620,7 +612,7 @@ public class OperationsService extends Service {
                     case ACTION_RENAME:
                         remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                         String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
-                        operation = new RenameFileOperation(remotePath, newName);
+                        operation = new RenameFileOperation(remotePath, newName, fileDataStorageManager);
                         break;
 
                     case ACTION_REMOVE:
@@ -632,12 +624,16 @@ public class OperationsService extends Service {
                                                             onlyLocalCopy,
                                                             account,
                                                             inBackground,
-                                                            getApplicationContext());
+                                                            getApplicationContext(),
+                                                            fileDataStorageManager);
                         break;
 
                     case ACTION_CREATE_FOLDER:
                         remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
-                        operation = new CreateFolderOperation(remotePath, user, getApplicationContext());
+                        operation = new CreateFolderOperation(remotePath,
+                                                              user,
+                                                              getApplicationContext(),
+                                                              fileDataStorageManager);
                         break;
 
                     case ACTION_SYNC_FILE:
@@ -646,7 +642,8 @@ public class OperationsService extends Service {
                         operation = new SynchronizeFileOperation(remotePath,
                                                                  user,
                                                                  syncFileContents,
-                                                                 getApplicationContext());
+                                                                 getApplicationContext(),
+                                                                 fileDataStorageManager);
                         break;
 
                     case ACTION_SYNC_FOLDER:
@@ -655,24 +652,25 @@ public class OperationsService extends Service {
                             this,                       // TODO remove this dependency from construction time
                             remotePath,
                             user,
-                            System.currentTimeMillis()  // TODO remove this dependency from construction time
+                            System.currentTimeMillis(),  // TODO remove this dependency from construction time
+                            fileDataStorageManager
                         );
                         break;
 
                     case ACTION_MOVE_FILE:
                         remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                         newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
-                        operation = new MoveFileOperation(remotePath, newParentPath);
+                        operation = new MoveFileOperation(remotePath, newParentPath, fileDataStorageManager);
                         break;
 
                     case ACTION_COPY_FILE:
                         remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                         newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
-                        operation = new CopyFileOperation(remotePath, newParentPath);
+                        operation = new CopyFileOperation(remotePath, newParentPath, fileDataStorageManager);
                         break;
 
                     case ACTION_CHECK_CURRENT_CREDENTIALS:
-                    operation = new CheckCurrentCredentialsOperation(user);
+                        operation = new CheckCurrentCredentialsOperation(user, fileDataStorageManager);
                         break;
 
                     case ACTION_RESTORE_VERSION:

+ 2 - 8
src/main/java/com/owncloud/android/services/SyncFolderHandler.java

@@ -28,7 +28,6 @@ import android.os.Message;
 import android.util.Pair;
 
 import com.nextcloud.client.account.User;
-import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.files.services.FileDownloader;
 import com.owncloud.android.files.services.IndexedForest;
@@ -58,7 +57,6 @@ class SyncFolderHandler extends Handler {
     private IndexedForest<SynchronizeFolderOperation> mPendingOperations = new IndexedForest<>();
 
     private Account mCurrentAccount;
-    private FileDataStorageManager mStorageManager;
     private SynchronizeFolderOperation mCurrentSyncOperation;
 
 
@@ -107,18 +105,14 @@ class SyncFolderHandler extends Handler {
 
                 if (mCurrentAccount == null || !mCurrentAccount.equals(account)) {
                     mCurrentAccount = account;
-                    mStorageManager = new FileDataStorageManager(
-                            account,
-                            mService.getContentResolver()
-                    );
-                }   // else, reuse storage manager from previous operation
+                }
 
                 // always get client from client manager, to get fresh credentials in case of update
                 OwnCloudAccount ocAccount = new OwnCloudAccount(account, mService);
                 OwnCloudClient mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
                         getClientFor(ocAccount, mService);
 
-                result = mCurrentSyncOperation.execute(mOwnCloudClient, mStorageManager);
+                result = mCurrentSyncOperation.execute(mOwnCloudClient);
                 sendBroadcastFinishedSyncFolder(account, remotePath, result.isSuccess());
                 mService.dispatchResultToOperationListeners(mCurrentSyncOperation, result);
 

+ 2 - 2
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -1124,8 +1124,8 @@ public abstract class DrawerActivity extends ToolbarActivity
                 // fetch capabilities as early as possible
                 if ((getCapabilities() == null || getCapabilities().getAccountName().isEmpty())
                     && getStorageManager() != null) {
-                    GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation();
-                    getCapabilities.execute(getStorageManager(), getBaseContext());
+                    GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager());
+                    getCapabilities.execute(getBaseContext());
                 }
 
                 User user = accountManager.getUser();

+ 16 - 7
src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

@@ -244,10 +244,15 @@ public class FileOperationsHelper {
 
     private void syncFile(OCFile file, User user, FileDataStorageManager storageManager) {
         fileActivity.runOnUiThread(() -> fileActivity.showLoadingDialog(fileActivity.getResources()
-                .getString(R.string.sync_in_progress)));
+                                                                            .getString(R.string.sync_in_progress)));
 
-        SynchronizeFileOperation sfo = new SynchronizeFileOperation(file, null, user, true, fileActivity);
-        RemoteOperationResult result = sfo.execute(storageManager, fileActivity);
+        SynchronizeFileOperation sfo = new SynchronizeFileOperation(file,
+                                                                    null,
+                                                                    user,
+                                                                    true,
+                                                                    fileActivity,
+                                                                    storageManager);
+        RemoteOperationResult result = sfo.execute(fileActivity);
 
         if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) {
             // ISSUE 5: if the user is not running the app (this is a service!),
@@ -309,13 +314,17 @@ public class FileOperationsHelper {
                 public void run() {
                     User user = currentAccount.getUser();
                     FileDataStorageManager storageManager =
-                            new FileDataStorageManager(user.toPlatformAccount(), fileActivity.getContentResolver());
+                        new FileDataStorageManager(user.toPlatformAccount(), fileActivity.getContentResolver());
                     // a fresh object is needed; many things could have occurred to the file
                     // since it was registered to observe again, assuming that local files
                     // are linked to a remote file AT MOST, SOMETHING TO BE DONE;
-                    SynchronizeFileOperation sfo =
-                            new SynchronizeFileOperation(file, null, user, true, fileActivity);
-                    RemoteOperationResult result = sfo.execute(storageManager, fileActivity);
+                    SynchronizeFileOperation sfo = new SynchronizeFileOperation(file,
+                                                                                null,
+                                                                                user,
+                                                                                true,
+                                                                                fileActivity,
+                                                                                storageManager);
+                    RemoteOperationResult result = sfo.execute(fileActivity);
                     fileActivity.dismissLoadingDialog();
                     if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) {
                         // ISSUE 5: if the user is not running the app (this is a service!),