Browse Source

only use FileDownloadWorker via manual sync

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 6 months ago
parent
commit
dbcfcca259

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

@@ -67,7 +67,7 @@ class InternalTwoWaySyncWork(
                 }
 
                 Log_OC.d(TAG, "Folder ${folder.remotePath}: started!")
-                operation = SynchronizeFolderOperation(context, folder.remotePath, user, fileDataStorageManager)
+                operation = SynchronizeFolderOperation(context, folder.remotePath, user, fileDataStorageManager, true)
                 val operationResult = operation?.execute(context)
 
                 if (operationResult?.isSuccess == true) {

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

@@ -77,7 +77,8 @@ class OfflineSyncWork constructor(
                     user,
                     true,
                     context,
-                    storageManager
+                    storageManager,
+                    true
                 )
                 synchronizeFileOperation.execute(context)
             }

+ 23 - 16
app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java

@@ -17,6 +17,7 @@ import android.content.Context;
 import android.text.TextUtils;
 
 import com.nextcloud.client.account.User;
+import com.nextcloud.client.jobs.download.FileDownloadHelper;
 import com.nextcloud.client.jobs.upload.FileUploadHelper;
 import com.nextcloud.client.jobs.upload.FileUploadWorker;
 import com.owncloud.android.datamodel.FileDataStorageManager;
@@ -45,6 +46,8 @@ public class SynchronizeFileOperation extends SyncOperation {
     private boolean mSyncFileContents;
     private Context mContext;
     private boolean mTransferWasRequested;
+    private boolean syncForInternalTwoWaySyncWorker;
+
 
     /**
      * When 'false', uploads to the server are not done; only downloads or conflict detection. This is a temporal
@@ -73,7 +76,8 @@ public class SynchronizeFileOperation extends SyncOperation {
         User user,
         boolean syncFileContents,
         Context context,
-        FileDataStorageManager storageManager) {
+        FileDataStorageManager storageManager,
+        boolean syncForInternalTwoWaySyncWorker) {
         super(storageManager);
 
         mRemotePath = remotePath;
@@ -83,6 +87,7 @@ public class SynchronizeFileOperation extends SyncOperation {
         mSyncFileContents = syncFileContents;
         mContext = context;
         mAllowUploads = true;
+        this.syncForInternalTwoWaySyncWorker = syncForInternalTwoWaySyncWorker;
     }
 
 
@@ -294,27 +299,29 @@ public class SynchronizeFileOperation extends SyncOperation {
     }
 
     private void requestForDownload(OCFile file) {
-        Log_OC.d("InternalTwoWaySyncWork", "download file: " + file.getFileName());
+        if (syncForInternalTwoWaySyncWorker) {
+            Log_OC.d("InternalTwoWaySyncWork", "download file: " + file.getFileName());
 
-        try {
-            final var operation = new DownloadFileOperation(mUser, file, mContext);
-            var result = operation.execute(getClient());
+            try {
+                final var operation = new DownloadFileOperation(mUser, file, mContext);
+                var result = operation.execute(getClient());
 
-            mTransferWasRequested = true;
+                mTransferWasRequested = true;
 
-            String filename = file.getFileName();
-            if (filename != null) {
-                if (result.isSuccess()) {
-                    Log_OC.d(TAG, "requestForDownload completed for: " + file.getFileName());
-                } else {
-                    Log_OC.d(TAG, "requestForDownload failed for: " + file.getFileName());
+                String filename = file.getFileName();
+                if (filename != null) {
+                    if (result.isSuccess()) {
+                        Log_OC.d(TAG, "requestForDownload completed for: " + file.getFileName());
+                    } else {
+                        Log_OC.d(TAG, "requestForDownload failed for: " + file.getFileName());
+                    }
                 }
+            } catch (Exception e) {
+                Log_OC.d(TAG, "Exception caught at requestForDownload" + e);
             }
-        } catch (Exception e) {
-            Log_OC.d(TAG, "Exception caught at requestForDownload" + e);
+        } else {
+            FileDownloadHelper.Companion.instance().downloadFile(mUser, file);
         }
-
-
     }
 
     public boolean transferWasRequested() {

+ 21 - 14
app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -15,6 +15,7 @@ import android.content.Intent;
 import android.text.TextUtils;
 
 import com.nextcloud.client.account.User;
+import com.nextcloud.client.jobs.download.FileDownloadHelper;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.e2e.v1.decrypted.DecryptedFolderMetadataFileV1;
@@ -85,6 +86,8 @@ public class SynchronizeFolderOperation extends SyncOperation {
 
     private final AtomicBoolean mCancellationRequested;
 
+    private final boolean syncForInternalTwoWaySyncWorker;
+
     /**
      * Creates a new instance of {@link SynchronizeFolderOperation}.
      *
@@ -95,7 +98,8 @@ public class SynchronizeFolderOperation extends SyncOperation {
     public SynchronizeFolderOperation(Context context,
                                       String remotePath,
                                       User user,
-                                      FileDataStorageManager storageManager) {
+                                      FileDataStorageManager storageManager,
+                                      boolean syncForInternalTwoWaySyncWorker) {
         super(storageManager);
 
         mRemotePath = remotePath;
@@ -105,6 +109,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
         mFilesForDirectDownload = new Vector<>();
         mFilesToSyncContents = new Vector<>();
         mCancellationRequested = new AtomicBoolean(false);
+        this.syncForInternalTwoWaySyncWorker = syncForInternalTwoWaySyncWorker;
     }
 
 
@@ -439,27 +444,29 @@ public class SynchronizeFolderOperation extends SyncOperation {
     }
 
     private void startDirectDownloads() {
-        try {
-            for (OCFile file: mFilesForDirectDownload) {
-                if (file != null) {
-                    // delay 1 second before each download
-                    Thread.sleep(1000);
+        if (syncForInternalTwoWaySyncWorker) {
+            try {
+                for (OCFile file: mFilesForDirectDownload) {
+                    if (file == null) continue;
 
                     final var operation = new DownloadFileOperation(user, file, mContext);
                     var result = operation.execute(getClient());
 
                     String filename = file.getFileName();
-                    if (filename != null) {
-                        if (result.isSuccess()) {
-                            Log_OC.d(TAG, "startDirectDownloads completed for: " + file.getFileName());
-                        } else {
-                            Log_OC.d(TAG, "startDirectDownloads failed for: " + file.getFileName());
-                        }
+                    if (filename == null) continue;
+
+                    if (result.isSuccess()) {
+                        Log_OC.d(TAG, "startDirectDownloads completed for: " + file.getFileName());
+                    } else {
+                        Log_OC.d(TAG, "startDirectDownloads failed for: " + file.getFileName());
                     }
                 }
+            } catch (Exception e) {
+                Log_OC.d(TAG, "Exception caught at startDirectDownloads" + e);
             }
-        } catch (Exception e) {
-            Log_OC.d(TAG, "Exception caught at startDirectDownloads" + e);
+        } else {
+            final var fileDownloadHelper = FileDownloadHelper.Companion.instance();
+            mFilesForDirectDownload.forEach(file -> fileDownloadHelper.downloadFile(user, file));
         }
     }
 

+ 4 - 2
app/src/main/java/com/owncloud/android/services/OperationsService.java

@@ -698,7 +698,8 @@ public class OperationsService extends Service {
                                                                  user,
                                                                  syncFileContents,
                                                                  getApplicationContext(),
-                                                                 fileDataStorageManager);
+                                                                 fileDataStorageManager,
+                                                                 false);
                         break;
 
                     case ACTION_SYNC_FOLDER:
@@ -707,7 +708,8 @@ public class OperationsService extends Service {
                             this,                       // TODO remove this dependency from construction time
                             remotePath,
                             user,
-                            fileDataStorageManager
+                            fileDataStorageManager,
+                            false
                         );
                         break;