Browse Source

Merge pull request #8647 from nextcloud/fixContactBackup

SyncOperations always need fileDataStorageManager: throw an Exception if not properly started
Tobias Kaminsky 3 years ago
parent
commit
16243c2909

+ 9 - 1
src/main/java/com/nextcloud/client/di/AppModule.java

@@ -52,6 +52,7 @@ import com.nextcloud.client.network.ClientFactory;
 import com.nextcloud.client.notifications.AppNotificationManager;
 import com.nextcloud.client.notifications.AppNotificationManager;
 import com.nextcloud.client.notifications.AppNotificationManagerImpl;
 import com.nextcloud.client.notifications.AppNotificationManagerImpl;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
 import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
 import com.owncloud.android.ui.activities.data.activities.ActivitiesServiceApi;
 import com.owncloud.android.ui.activities.data.activities.ActivitiesServiceApi;
@@ -135,7 +136,14 @@ class AppModule {
         return new UploadsStorageManager(currentAccountProvider, context.getContentResolver());
         return new UploadsStorageManager(currentAccountProvider, context.getContentResolver());
     }
     }
 
 
-    @Provides CurrentAccountProvider currentAccountProvider(UserAccountManager accountManager) {
+    @Provides
+    FileDataStorageManager fileDataStorageManager(CurrentAccountProvider currentAccountProvider,
+                                                  Context context) {
+        return new FileDataStorageManager(currentAccountProvider.getCurrentAccount(), context.getContentResolver());
+    }
+
+    @Provides
+    CurrentAccountProvider currentAccountProvider(UserAccountManager accountManager) {
         return accountManager;
         return accountManager;
     }
     }
 
 

+ 6 - 1
src/main/java/com/nextcloud/client/files/downloader/FileTransferService.kt

@@ -31,6 +31,7 @@ import com.nextcloud.client.logger.Logger
 import com.nextcloud.client.network.ClientFactory
 import com.nextcloud.client.network.ClientFactory
 import com.nextcloud.client.network.ConnectivityService
 import com.nextcloud.client.network.ConnectivityService
 import com.nextcloud.client.notifications.AppNotificationManager
 import com.nextcloud.client.notifications.AppNotificationManager
+import com.owncloud.android.datamodel.FileDataStorageManager
 import com.owncloud.android.datamodel.UploadsStorageManager
 import com.owncloud.android.datamodel.UploadsStorageManager
 import dagger.android.AndroidInjection
 import dagger.android.AndroidInjection
 import javax.inject.Inject
 import javax.inject.Inject
@@ -89,6 +90,9 @@ class FileTransferService : Service() {
     @Inject
     @Inject
     lateinit var powerManagementService: PowerManagementService
     lateinit var powerManagementService: PowerManagementService
 
 
+    @Inject
+    lateinit var fileDataStorageManager: FileDataStorageManager
+
     val isRunning: Boolean get() = downloaders.any { it.value.isRunning }
     val isRunning: Boolean get() = downloaders.any { it.value.isRunning }
 
 
     private val downloaders: MutableMap<String, TransferManagerImpl> = mutableMapOf()
     private val downloaders: MutableMap<String, TransferManagerImpl> = mutableMapOf()
@@ -169,7 +173,8 @@ class FileTransferService : Service() {
                 uploadsStorageManager,
                 uploadsStorageManager,
                 connectivityService,
                 connectivityService,
                 powerManagementService,
                 powerManagementService,
-                { clientFactory.create(user) }
+                { clientFactory.create(user) },
+                fileDataStorageManager
             )
             )
             val newDownloader = TransferManagerImpl(runner, downloadTaskFactory, uploadTaskFactory)
             val newDownloader = TransferManagerImpl(runner, downloadTaskFactory, uploadTaskFactory)
             newDownloader.registerTransferListener(this::onTransferUpdate)
             newDownloader.registerTransferListener(this::onTransferUpdate)

+ 8 - 4
src/main/java/com/nextcloud/client/files/downloader/UploadTask.kt

@@ -23,6 +23,7 @@ import android.content.Context
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.User
 import com.nextcloud.client.device.PowerManagementService
 import com.nextcloud.client.device.PowerManagementService
 import com.nextcloud.client.network.ConnectivityService
 import com.nextcloud.client.network.ConnectivityService
+import com.owncloud.android.datamodel.FileDataStorageManager
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.UploadsStorageManager
 import com.owncloud.android.datamodel.UploadsStorageManager
 import com.owncloud.android.db.OCUpload
 import com.owncloud.android.db.OCUpload
@@ -36,7 +37,8 @@ class UploadTask(
     private val uploadsStorageManager: UploadsStorageManager,
     private val uploadsStorageManager: UploadsStorageManager,
     private val connectivityService: ConnectivityService,
     private val connectivityService: ConnectivityService,
     private val powerManagementService: PowerManagementService,
     private val powerManagementService: PowerManagementService,
-    private val clientProvider: () -> OwnCloudClient
+    private val clientProvider: () -> OwnCloudClient,
+    private val fileDataStorageManager: FileDataStorageManager,
 ) {
 ) {
 
 
     data class Result(val file: OCFile, val success: Boolean)
     data class Result(val file: OCFile, val success: Boolean)
@@ -51,7 +53,8 @@ class UploadTask(
         private val uploadsStorageManager: UploadsStorageManager,
         private val uploadsStorageManager: UploadsStorageManager,
         private val connectivityService: ConnectivityService,
         private val connectivityService: ConnectivityService,
         private val powerManagementService: PowerManagementService,
         private val powerManagementService: PowerManagementService,
-        private val clientProvider: () -> OwnCloudClient
+        private val clientProvider: () -> OwnCloudClient,
+        private val fileDataStorageManager: FileDataStorageManager
     ) {
     ) {
         fun create(): UploadTask {
         fun create(): UploadTask {
             return UploadTask(
             return UploadTask(
@@ -59,7 +62,8 @@ class UploadTask(
                 uploadsStorageManager,
                 uploadsStorageManager,
                 connectivityService,
                 connectivityService,
                 powerManagementService,
                 powerManagementService,
-                clientProvider
+                clientProvider,
+                fileDataStorageManager
             )
             )
         }
         }
     }
     }
@@ -86,7 +90,7 @@ class UploadTask(
         )
         )
         val client = clientProvider()
         val client = clientProvider()
         uploadsStorageManager.updateDatabaseUploadStart(op)
         uploadsStorageManager.updateDatabaseUploadStart(op)
-        val result = op.execute(client)
+        val result = op.execute(client, fileDataStorageManager)
         uploadsStorageManager.updateDatabaseUploadResult(result, op)
         uploadsStorageManager.updateDatabaseUploadResult(result, op)
         return Result(file, result.isSuccess)
         return Result(file, result.isSuccess)
     }
     }

+ 1 - 1
src/main/java/com/nextcloud/client/jobs/ContactsBackupWork.kt

@@ -162,7 +162,7 @@ class ContactsBackupWork(
             }
             }
         }
         }
 
 
-        val request = UploadRequest.Builder(user = user, source = file.absolutePath, destination = backupFolder + file)
+        val request = UploadRequest.Builder(user, file.absolutePath, backupFolder + file.name)
             .setFileSize(file.length())
             .setFileSize(file.length())
             .setNameConflicPolicy(NameCollisionPolicy.RENAME)
             .setNameConflicPolicy(NameCollisionPolicy.RENAME)
             .setCreateRemoteFolder(true)
             .setCreateRemoteFolder(true)

+ 11 - 4
src/main/java/com/owncloud/android/operations/common/SyncOperation.java

@@ -138,16 +138,23 @@ public abstract class SyncOperation extends RemoteOperation {
 	 * @param listenerHandler	Handler associated to the thread where the methods of
 	 * @param listenerHandler	Handler associated to the thread where the methods of
      *                          the listener objects must be called.
      *                          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,
+     */
+    public Thread execute(OwnCloudClient client, FileDataStorageManager storageManager,
                           OnRemoteOperationListener listener, Handler listenerHandler) {
                           OnRemoteOperationListener listener, Handler listenerHandler) {
         if (storageManager == null) {
         if (storageManager == null) {
             throw new IllegalArgumentException("Trying to execute a sync operation " +
             throw new IllegalArgumentException("Trying to execute a sync operation " +
-                    "with a NULL storage manager");
+                                                   "with a NULL storage manager");
         }
         }
         this.storageManager = storageManager;
         this.storageManager = storageManager;
         return super.execute(client, listener, 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() {
     public FileDataStorageManager getStorageManager() {
         return this.storageManager;
         return this.storageManager;