From b7479c15725c0581cb00edfd6fdcd9e4592d8807 Mon Sep 17 00:00:00 2001 From: Dariusz Olszewski Date: Tue, 12 Mar 2024 22:43:09 +0100 Subject: [PATCH 01/11] fix(notifications): Workaround/fix for NEW_NOTIFICATION messages Signed-off-by: Dariusz Olszewski --- .../firebase/NCFirebaseMessagingService.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/app/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java b/app/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java index 45e4c98669..839d161c63 100644 --- a/app/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java +++ b/app/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java @@ -20,8 +20,10 @@ */ package com.owncloud.android.services.firebase; +import android.content.Intent; import android.text.TextUtils; +import com.google.firebase.messaging.Constants.MessageNotificationKeys; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; import com.nextcloud.client.account.UserAccountManager; @@ -29,6 +31,7 @@ import com.nextcloud.client.jobs.BackgroundJobManager; import com.nextcloud.client.jobs.NotificationWork; import com.nextcloud.client.preferences.AppPreferences; import com.owncloud.android.R; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.utils.PushUtils; import java.util.Map; @@ -43,14 +46,55 @@ public class NCFirebaseMessagingService extends FirebaseMessagingService { @Inject UserAccountManager accountManager; @Inject BackgroundJobManager backgroundJobManager; + static final String TAG = "NCFirebaseMessagingService"; + + // Firebase Messaging may apparently use two intent extras to specify a notification message. + // + // See the following fragments in https://github.com/firebase/firebase-android-sdk/blob/releases/m144_1.release/ + // firebase-messaging/src/main/java/com/google/firebase/messaging/FirebaseMessagingService.java#L223 + // firebase-messaging/src/main/java/com/google/firebase/messaging/NotificationParams.java#L419 + // firebase-messaging/src/main/java/com/google/firebase/messaging/Constants.java#L158 + // + // The "old" key is not exposed in com.google.firebase.messaging.Constants.MessageNotificationKeys, + // so we need to define it ourselves. + static final String ENABLE_NOTIFICATION_OLD = MessageNotificationKeys.NOTIFICATION_PREFIX_OLD + "e"; + static final String ENABLE_NOTIFICATION_NEW = MessageNotificationKeys.ENABLE_NOTIFICATION; + @Override public void onCreate() { super.onCreate(); AndroidInjection.inject(this); } + @Override + public void handleIntent(Intent intent) { + Log_OC.d(TAG, "handleIntent - extras: " + + ENABLE_NOTIFICATION_NEW + ": " + intent.getExtras().getString(ENABLE_NOTIFICATION_NEW) + ", " + + ENABLE_NOTIFICATION_OLD + ": " + intent.getExtras().getString(ENABLE_NOTIFICATION_OLD)); + + // When the app is in background and one of the ENABLE_NOTIFICATION or ENABLE_NOTIFICATION_OLD extras is set + // to "1" in the intent sent from the FCM system code to the FirebaseMessagingService in the application, + // the FCM library code that handles the intent DOES NOT invoke the onMessageReceived method. + // It just displays the notification by itself. + // + // In our case the original FCM message contains dummy values "NEW_NOTIFICATION" and we need to get the + // message in onMessageReceived to decrypt it. + // + // So we cheat here a little, by telling the FCM library that the notification flag is not set. + // + // Code below depends on implementation details of the firebase-messaging library (Firebase Android SDK). + // https://github.com/firebase/firebase-android-sdk/tree/master/firebase-messaging + + intent.removeExtra(ENABLE_NOTIFICATION_OLD); + intent.removeExtra(ENABLE_NOTIFICATION_NEW); + intent.putExtra(ENABLE_NOTIFICATION_NEW, "0"); + + super.handleIntent(intent); + } + @Override public void onMessageReceived(@NonNull RemoteMessage remoteMessage) { + Log_OC.d(TAG, "onMessageReceived"); final Map data = remoteMessage.getData(); final String subject = data.get(NotificationWork.KEY_NOTIFICATION_SUBJECT); final String signature = data.get(NotificationWork.KEY_NOTIFICATION_SIGNATURE); @@ -61,6 +105,7 @@ public class NCFirebaseMessagingService extends FirebaseMessagingService { @Override public void onNewToken(@NonNull String newToken) { + Log_OC.d(TAG, "onNewToken"); super.onNewToken(newToken); if (!TextUtils.isEmpty(getResources().getString(R.string.push_server_url))) { From 07ef42de726d259665d281d4fe877c2b909aa15f Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 7 Nov 2024 09:28:17 +0100 Subject: [PATCH 02/11] check folder path before upload Signed-off-by: alperozturk --- .../owncloud/android/ui/activity/FileDisplayActivity.java | 7 +++++++ .../owncloud/android/ui/activity/UploadFilesActivity.java | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index b7b9b2dc14..aeb3766fd5 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -68,6 +68,7 @@ import com.nextcloud.utils.extensions.ActivityExtensionsKt; import com.nextcloud.utils.extensions.BundleExtensionsKt; import com.nextcloud.utils.extensions.FileExtensionsKt; import com.nextcloud.utils.extensions.IntentExtensionsKt; +import com.nextcloud.utils.fileNameValidator.FileNameValidator; import com.nextcloud.utils.view.FastScrollUtils; import com.owncloud.android.MainApp; import com.owncloud.android.R; @@ -952,6 +953,12 @@ public class FileDisplayActivity extends FileActivity connectivityService.isNetworkAndServerAvailable(result -> { if (result) { + boolean isValidFolderPath = FileNameValidator.INSTANCE.checkFolderPath(remotePathBase,getCapabilities(),this); + if (!isValidFolderPath) { + DisplayUtils.showSnackMessage(this, R.string.file_name_validator_error_contains_reserved_names_or_invalid_characters); + return; + } + FileUploadHelper.Companion.instance().uploadNewFiles(getUser().orElseThrow(RuntimeException::new), filePaths, decryptedRemotePaths, diff --git a/app/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java index 6ffc78b23c..9b7514bd01 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java @@ -35,7 +35,6 @@ import com.nextcloud.client.jobs.upload.FileUploadWorker; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.utils.extensions.ActivityExtensionsKt; import com.nextcloud.utils.extensions.FileExtensionsKt; -import com.nextcloud.utils.fileNameValidator.FileNameValidator; import com.owncloud.android.R; import com.owncloud.android.databinding.UploadFilesLayoutBinding; import com.owncloud.android.lib.common.utils.Log_OC; @@ -60,7 +59,6 @@ import javax.inject.Inject; import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.SearchView; import androidx.core.view.MenuItemCompat; From 190d0a9bab45d4015d5a2f8a3fa6652ed6000333 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 11 Nov 2024 11:50:20 +0100 Subject: [PATCH 03/11] add mCancellationRequested call Signed-off-by: alperozturk --- .../nextcloud/client/jobs/InternalTwoWaySyncWork.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt b/app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt index fda84ce361..4de97810ba 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt @@ -32,6 +32,7 @@ class InternalTwoWaySyncWork( private val appPreferences: AppPreferences ) : Worker(context, params) { private var shouldRun = true + private var operation: SynchronizeFolderOperation? = null override fun doWork(): Result { Log_OC.d(TAG, "Worker started!") @@ -66,10 +67,10 @@ class InternalTwoWaySyncWork( } Log_OC.d(TAG, "Folder ${folder.remotePath}: started!") - val operation = SynchronizeFolderOperation(context, folder.remotePath, user, fileDataStorageManager) - .execute(context) + operation = SynchronizeFolderOperation(context, folder.remotePath, user, fileDataStorageManager) + val operationResult = operation?.execute(context) - if (operation.isSuccess) { + if (operationResult?.isSuccess == true) { Log_OC.d(TAG, "Folder ${folder.remotePath}: finished!") } else { Log_OC.d(TAG, "Folder ${folder.remotePath} failed!") @@ -77,7 +78,10 @@ class InternalTwoWaySyncWork( } folder.apply { - internalFolderSyncResult = operation.code.toString() + operationResult?.let { + internalFolderSyncResult = it.code.toString() + } + internalFolderSyncTimestamp = System.currentTimeMillis() } @@ -96,6 +100,7 @@ class InternalTwoWaySyncWork( override fun onStopped() { Log_OC.d(TAG, "OnStopped of worker called!") + operation?.cancel() shouldRun = false super.onStopped() } From f15c017174f8a24bdb542171328345986d00d441 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 11 Nov 2024 11:58:05 +0100 Subject: [PATCH 04/11] dont use FileDownloadWorker in SynchronizeFolderOperation Signed-off-by: alperozturk --- .../SynchronizeFolderOperation.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java index c4e4bf05c0..1f9d99975e 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -15,7 +15,6 @@ 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; @@ -40,7 +39,6 @@ import java.util.List; import java.util.Map; import java.util.Vector; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Consumer; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -441,8 +439,28 @@ public class SynchronizeFolderOperation extends SyncOperation { } private void startDirectDownloads() { - final var fileDownloadHelper = FileDownloadHelper.Companion.instance(); - mFilesForDirectDownload.forEach(file -> fileDownloadHelper.downloadFile(user, file)); + try { + for (OCFile file: mFilesForDirectDownload) { + if (file != null) { + // delay 1 second before each download + Thread.sleep(1000); + + 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()); + } + } + } + } + } catch (Exception e) { + Log_OC.d(TAG, "Exception caught at startDirectDownloads" + e); + } } /** From e48cb5aee41f82f65cce833e1580674a6725de63 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 11 Nov 2024 11:59:29 +0100 Subject: [PATCH 05/11] dont use FileDownloadWorker in SynchronizeFileOperation Signed-off-by: alperozturk --- .../operations/SynchronizeFileOperation.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java index 6caf81f471..47a6df9530 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -17,7 +17,6 @@ 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; @@ -296,10 +295,22 @@ public class SynchronizeFileOperation extends SyncOperation { private void requestForDownload(OCFile file) { Log_OC.d("InternalTwoWaySyncWork", "download file: " + file.getFileName()); - - FileDownloadHelper.Companion.instance().downloadFile( - mUser, - file); + + try { + final var operation = new DownloadFileOperation(mUser, file, mContext); + var result = operation.execute(getClient()); + + 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); + } mTransferWasRequested = true; } From db547427f4a3861ebad8dcc0fc138ef6677d50d6 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 11 Nov 2024 12:04:02 +0100 Subject: [PATCH 06/11] fix usage of mTransferWasRequested Signed-off-by: alperozturk --- .../owncloud/android/operations/SynchronizeFileOperation.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java index 47a6df9530..4ca4753f35 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -300,6 +300,8 @@ public class SynchronizeFileOperation extends SyncOperation { final var operation = new DownloadFileOperation(mUser, file, mContext); var result = operation.execute(getClient()); + mTransferWasRequested = true; + String filename = file.getFileName(); if (filename != null) { if (result.isSuccess()) { @@ -312,7 +314,7 @@ public class SynchronizeFileOperation extends SyncOperation { Log_OC.d(TAG, "Exception caught at requestForDownload" + e); } - mTransferWasRequested = true; + } public boolean transferWasRequested() { From dbcfcca2592efa238975cb46d8aab86c8cc72599 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 11 Nov 2024 12:46:58 +0100 Subject: [PATCH 07/11] only use FileDownloadWorker via manual sync Signed-off-by: alperozturk --- .../client/jobs/InternalTwoWaySyncWork.kt | 2 +- .../nextcloud/client/jobs/OfflineSyncWork.kt | 3 +- .../operations/SynchronizeFileOperation.java | 39 +++++++++++-------- .../SynchronizeFolderOperation.java | 35 ++++++++++------- .../android/services/OperationsService.java | 6 ++- 5 files changed, 51 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt b/app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt index 4de97810ba..1d1c89fd9d 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt +++ b/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) { diff --git a/app/src/main/java/com/nextcloud/client/jobs/OfflineSyncWork.kt b/app/src/main/java/com/nextcloud/client/jobs/OfflineSyncWork.kt index 84663a9786..99f6481cf9 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/OfflineSyncWork.kt +++ b/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) } diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java index 4ca4753f35..62fa46b36d 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/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() { diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java index 1f9d99975e..c187bf2852 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/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)); } } diff --git a/app/src/main/java/com/owncloud/android/services/OperationsService.java b/app/src/main/java/com/owncloud/android/services/OperationsService.java index 648c7ce1b4..0cd2d5e30a 100644 --- a/app/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/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; From d8e951ecaaacc9c7e8a0e01e24ff4b1a0bbe736c Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 11 Nov 2024 12:53:23 +0100 Subject: [PATCH 08/11] add missing constructor usages Signed-off-by: alperozturk --- .../android/operations/SynchronizeFileOperation.java | 10 ++++++---- .../android/operations/SynchronizeFolderOperation.java | 6 ++++-- .../android/ui/helpers/FileOperationsHelper.java | 6 ++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java index 62fa46b36d..cdd5b79535 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -114,7 +114,8 @@ public class SynchronizeFileOperation extends SyncOperation { User user, boolean syncFileContents, Context context, - FileDataStorageManager storageManager) { + FileDataStorageManager storageManager, + boolean syncForInternalTwoWaySyncWorker) { super(storageManager); mLocalFile = localFile; @@ -134,6 +135,7 @@ public class SynchronizeFileOperation extends SyncOperation { mSyncFileContents = syncFileContents; mContext = context; mAllowUploads = true; + this.syncForInternalTwoWaySyncWorker = syncForInternalTwoWaySyncWorker; } @@ -163,9 +165,9 @@ public class SynchronizeFileOperation extends SyncOperation { boolean syncFileContents, boolean allowUploads, Context context, - FileDataStorageManager storageManager) { - - this(localFile, serverFile, user, syncFileContents, context, storageManager); + FileDataStorageManager storageManager, + boolean syncForInternalTwoWaySyncWorker) { + this(localFile, serverFile, user, syncFileContents, context, storageManager, syncForInternalTwoWaySyncWorker); mAllowUploads = allowUploads; } diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java index c187bf2852..383ec7a034 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -409,7 +409,8 @@ public class SynchronizeFolderOperation extends SyncOperation { user, true, mContext, - getStorageManager() + getStorageManager(), + syncForInternalTwoWaySyncWorker ); mFilesToSyncContents.add(operation); } @@ -430,7 +431,8 @@ public class SynchronizeFolderOperation extends SyncOperation { user, true, mContext, - getStorageManager() + getStorageManager(), + syncForInternalTwoWaySyncWorker ); mFilesToSyncContents.add(operation); } diff --git a/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index 25a5e4a739..6b765c2afd 100755 --- a/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -225,7 +225,8 @@ public class FileOperationsHelper { user, true, fileActivity, - storageManager); + storageManager, + false); RemoteOperationResult result = sfo.execute(fileActivity); if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) { @@ -303,7 +304,8 @@ public class FileOperationsHelper { user, true, fileActivity, - storageManager); + storageManager, + false); RemoteOperationResult result = sfo.execute(fileActivity); fileActivity.dismissLoadingDialog(); if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) { From 846b70191638cf9eb5a8ed546bbf08ab73a43f9f Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 11 Nov 2024 14:39:03 +0100 Subject: [PATCH 09/11] rename boolean flag Signed-off-by: alperozturk --- .../operations/SynchronizeFileOperation.java | 16 ++++++++-------- .../operations/SynchronizeFolderOperation.java | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java index cdd5b79535..7c66d1128f 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -46,7 +46,7 @@ public class SynchronizeFileOperation extends SyncOperation { private boolean mSyncFileContents; private Context mContext; private boolean mTransferWasRequested; - private boolean syncForInternalTwoWaySyncWorker; + private final boolean syncInBackgroundWorker; /** @@ -77,7 +77,7 @@ public class SynchronizeFileOperation extends SyncOperation { boolean syncFileContents, Context context, FileDataStorageManager storageManager, - boolean syncForInternalTwoWaySyncWorker) { + boolean syncInBackgroundWorker) { super(storageManager); mRemotePath = remotePath; @@ -87,7 +87,7 @@ public class SynchronizeFileOperation extends SyncOperation { mSyncFileContents = syncFileContents; mContext = context; mAllowUploads = true; - this.syncForInternalTwoWaySyncWorker = syncForInternalTwoWaySyncWorker; + this.syncInBackgroundWorker = syncInBackgroundWorker; } @@ -115,7 +115,7 @@ public class SynchronizeFileOperation extends SyncOperation { boolean syncFileContents, Context context, FileDataStorageManager storageManager, - boolean syncForInternalTwoWaySyncWorker) { + boolean syncInBackgroundWorker) { super(storageManager); mLocalFile = localFile; @@ -135,7 +135,7 @@ public class SynchronizeFileOperation extends SyncOperation { mSyncFileContents = syncFileContents; mContext = context; mAllowUploads = true; - this.syncForInternalTwoWaySyncWorker = syncForInternalTwoWaySyncWorker; + this.syncInBackgroundWorker = syncInBackgroundWorker; } @@ -166,8 +166,8 @@ public class SynchronizeFileOperation extends SyncOperation { boolean allowUploads, Context context, FileDataStorageManager storageManager, - boolean syncForInternalTwoWaySyncWorker) { - this(localFile, serverFile, user, syncFileContents, context, storageManager, syncForInternalTwoWaySyncWorker); + boolean syncInBackgroundWorker) { + this(localFile, serverFile, user, syncFileContents, context, storageManager, syncInBackgroundWorker); mAllowUploads = allowUploads; } @@ -301,7 +301,7 @@ public class SynchronizeFileOperation extends SyncOperation { } private void requestForDownload(OCFile file) { - if (syncForInternalTwoWaySyncWorker) { + if (syncInBackgroundWorker) { Log_OC.d("InternalTwoWaySyncWork", "download file: " + file.getFileName()); try { diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java index 383ec7a034..3af3f7e1ac 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -86,7 +86,7 @@ public class SynchronizeFolderOperation extends SyncOperation { private final AtomicBoolean mCancellationRequested; - private final boolean syncForInternalTwoWaySyncWorker; + private final boolean syncInBackgroundWorker; /** * Creates a new instance of {@link SynchronizeFolderOperation}. @@ -99,7 +99,7 @@ public class SynchronizeFolderOperation extends SyncOperation { String remotePath, User user, FileDataStorageManager storageManager, - boolean syncForInternalTwoWaySyncWorker) { + boolean syncInBackgroundWorker) { super(storageManager); mRemotePath = remotePath; @@ -109,7 +109,7 @@ public class SynchronizeFolderOperation extends SyncOperation { mFilesForDirectDownload = new Vector<>(); mFilesToSyncContents = new Vector<>(); mCancellationRequested = new AtomicBoolean(false); - this.syncForInternalTwoWaySyncWorker = syncForInternalTwoWaySyncWorker; + this.syncInBackgroundWorker = syncInBackgroundWorker; } @@ -410,7 +410,7 @@ public class SynchronizeFolderOperation extends SyncOperation { true, mContext, getStorageManager(), - syncForInternalTwoWaySyncWorker + syncInBackgroundWorker ); mFilesToSyncContents.add(operation); } @@ -432,7 +432,7 @@ public class SynchronizeFolderOperation extends SyncOperation { true, mContext, getStorageManager(), - syncForInternalTwoWaySyncWorker + syncInBackgroundWorker ); mFilesToSyncContents.add(operation); } @@ -446,7 +446,7 @@ public class SynchronizeFolderOperation extends SyncOperation { } private void startDirectDownloads() { - if (syncForInternalTwoWaySyncWorker) { + if (syncInBackgroundWorker) { try { for (OCFile file: mFilesForDirectDownload) { if (file == null) continue; From c45d8394e25d6b960d55c92702132c6858242085 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 11 Nov 2024 14:42:25 +0100 Subject: [PATCH 10/11] add curly bracket for condition checks Signed-off-by: alperozturk --- .../android/operations/SynchronizeFolderOperation.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java index 3af3f7e1ac..a4cf8d9358 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -449,13 +449,17 @@ public class SynchronizeFolderOperation extends SyncOperation { if (syncInBackgroundWorker) { try { for (OCFile file: mFilesForDirectDownload) { - if (file == null) continue; + if (file == null) { + continue; + } final var operation = new DownloadFileOperation(user, file, mContext); var result = operation.execute(getClient()); String filename = file.getFileName(); - if (filename == null) continue; + if (filename == null) { + continue; + } if (result.isSuccess()) { Log_OC.d(TAG, "startDirectDownloads completed for: " + file.getFileName()); From b85affb3f975b087548a2655b55ecfdff01a0dba Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 11 Nov 2024 14:44:07 +0100 Subject: [PATCH 11/11] check mCancellationRequested in for loop Signed-off-by: alperozturk --- .../android/operations/SynchronizeFolderOperation.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java index a4cf8d9358..1879e8b042 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -449,6 +449,12 @@ public class SynchronizeFolderOperation extends SyncOperation { if (syncInBackgroundWorker) { try { for (OCFile file: mFilesForDirectDownload) { + synchronized (mCancellationRequested) { + if (mCancellationRequested.get()) { + break; + } + } + if (file == null) { continue; }