ソースを参照

Rebase master

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 年間 前
コミット
7d20b3e62a
29 ファイル変更260 行追加255 行削除
  1. 2 2
      app/src/androidTest/java/com/owncloud/android/AbstractIT.java
  2. 4 4
      app/src/androidTest/java/com/owncloud/android/AbstractOnServerIT.java
  3. 23 23
      app/src/androidTest/java/com/owncloud/android/UploadIT.java
  4. 15 15
      app/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt
  5. 2 2
      app/src/androidTest/java/com/owncloud/android/ui/helpers/UriUploaderIT.kt
  6. 1 1
      app/src/main/AndroidManifest.xml
  7. 2 2
      app/src/main/java/com/nextcloud/client/documentscan/DocumentScanViewModel.kt
  8. 2 2
      app/src/main/java/com/nextcloud/client/documentscan/GeneratePdfFromImagesWork.kt
  9. 2 2
      app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt
  10. 5 5
      app/src/main/java/com/nextcloud/client/files/upload/PostUploadAction.kt
  11. 77 68
      app/src/main/java/com/nextcloud/client/files/uploader/FileUploadWorker.kt
  12. 16 18
      app/src/main/java/com/nextcloud/client/files/uploader/FileUploaderDelegate.kt
  13. 4 5
      app/src/main/java/com/nextcloud/client/files/uploader/FileUploaderIntents.kt
  14. 3 4
      app/src/main/java/com/nextcloud/client/files/uploader/UploadNotificationManager.kt
  15. 5 4
      app/src/main/java/com/nextcloud/client/jobs/BackgroundJobFactory.kt
  16. 17 4
      app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt
  17. 5 4
      app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt
  18. 27 0
      app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt
  19. 2 2
      app/src/main/java/com/owncloud/android/db/OCUpload.java
  20. 6 6
      app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java
  21. 3 3
      app/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java
  22. 3 3
      app/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.kt
  23. 2 2
      app/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java
  24. 5 7
      app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java
  25. 4 4
      app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java
  26. 7 7
      app/src/main/java/com/owncloud/android/ui/dialog/parcel/SyncedFolderParcelable.java
  27. 2 5
      app/src/main/java/com/owncloud/android/utils/FilesSyncHelper.java
  28. 12 49
      app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt
  29. 2 2
      app/src/test/java/com/owncloud/android/ui/activity/SyncedFoldersActivityTest.java

+ 2 - 2
app/src/androidTest/java/com/owncloud/android/AbstractIT.java

@@ -21,7 +21,7 @@ import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.account.UserAccountManagerImpl;
 import com.nextcloud.client.device.BatteryStatus;
 import com.nextcloud.client.device.PowerManagementService;
-import com.nextcloud.client.jobs.FilesUploadWorker;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.nextcloud.client.network.Connectivity;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.client.preferences.AppPreferencesImpl;
@@ -400,7 +400,7 @@ public abstract class AbstractIT {
             null,
             ocUpload,
             NameCollisionPolicy.DEFAULT,
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             targetContext,
             false,
             false,

+ 4 - 4
app/src/androidTest/java/com/owncloud/android/AbstractOnServerIT.java

@@ -13,7 +13,7 @@ import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.account.UserAccountManagerImpl;
 import com.nextcloud.client.device.BatteryStatus;
 import com.nextcloud.client.device.PowerManagementService;
-import com.nextcloud.client.jobs.FilesUploadWorker;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.nextcloud.client.network.Connectivity;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.java.util.Optional;
@@ -178,7 +178,7 @@ public abstract class AbstractOnServerIT extends AbstractIT {
     }
 
     public void uploadOCUpload(OCUpload ocUpload) {
-        uploadOCUpload(ocUpload, FilesUploadWorker.LOCAL_BEHAVIOUR_COPY);
+        uploadOCUpload(ocUpload, FileUploadWorker.LOCAL_BEHAVIOUR_COPY);
     }
 
     public void uploadOCUpload(OCUpload ocUpload, int localBehaviour) {
@@ -253,8 +253,8 @@ public abstract class AbstractOnServerIT extends AbstractIT {
         assertNotNull(uploadedFile.getRemoteId());
         assertNotNull(uploadedFile.getPermissions());
 
-        if (localBehaviour == FilesUploadWorker.LOCAL_BEHAVIOUR_COPY ||
-            localBehaviour == FilesUploadWorker.LOCAL_BEHAVIOUR_MOVE) {
+        if (localBehaviour == FileUploadWorker.LOCAL_BEHAVIOUR_COPY ||
+            localBehaviour == FileUploadWorker.LOCAL_BEHAVIOUR_MOVE) {
             assertTrue(new File(uploadedFile.getStoragePath()).exists());
         }
     }

+ 23 - 23
app/src/androidTest/java/com/owncloud/android/UploadIT.java

@@ -24,7 +24,7 @@ package com.owncloud.android;
 import com.nextcloud.client.account.UserAccountManagerImpl;
 import com.nextcloud.client.device.BatteryStatus;
 import com.nextcloud.client.device.PowerManagementService;
-import com.nextcloud.client.jobs.FilesUploadWorker;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.nextcloud.client.network.Connectivity;
 import com.nextcloud.client.network.ConnectivityService;
 import com.owncloud.android.datamodel.OCFile;
@@ -134,7 +134,7 @@ public class UploadIT extends AbstractOnServerIT {
                                          FOLDER + "nonEmpty.txt",
                                          account.name);
 
-        uploadOCUpload(ocUpload, FilesUploadWorker.LOCAL_BEHAVIOUR_COPY);
+        uploadOCUpload(ocUpload, FileUploadWorker.LOCAL_BEHAVIOUR_COPY);
 
         File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
         OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
@@ -150,7 +150,7 @@ public class UploadIT extends AbstractOnServerIT {
                                          FOLDER + "nonEmpty.txt",
                                          account.name);
 
-        uploadOCUpload(ocUpload, FilesUploadWorker.LOCAL_BEHAVIOUR_MOVE);
+        uploadOCUpload(ocUpload, FileUploadWorker.LOCAL_BEHAVIOUR_MOVE);
 
         File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
         OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
@@ -166,7 +166,7 @@ public class UploadIT extends AbstractOnServerIT {
                                          FOLDER + "nonEmpty.txt",
                                          account.name);
 
-        uploadOCUpload(ocUpload, FilesUploadWorker.LOCAL_BEHAVIOUR_FORGET);
+        uploadOCUpload(ocUpload, FileUploadWorker.LOCAL_BEHAVIOUR_FORGET);
 
         File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
         OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
@@ -182,7 +182,7 @@ public class UploadIT extends AbstractOnServerIT {
                                          FOLDER + "nonEmpty.txt",
                                          account.name);
 
-        uploadOCUpload(ocUpload, FilesUploadWorker.LOCAL_BEHAVIOUR_DELETE);
+        uploadOCUpload(ocUpload, FileUploadWorker.LOCAL_BEHAVIOUR_DELETE);
 
         File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
         OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
@@ -222,7 +222,7 @@ public class UploadIT extends AbstractOnServerIT {
             null,
             ocUpload,
             NameCollisionPolicy.DEFAULT,
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             targetContext,
             false,
             true,
@@ -270,7 +270,7 @@ public class UploadIT extends AbstractOnServerIT {
             null,
             ocUpload,
             NameCollisionPolicy.DEFAULT,
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             targetContext,
             false,
             true,
@@ -315,7 +315,7 @@ public class UploadIT extends AbstractOnServerIT {
             null,
             ocUpload,
             NameCollisionPolicy.DEFAULT,
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             targetContext,
             true,
             false,
@@ -345,7 +345,7 @@ public class UploadIT extends AbstractOnServerIT {
             null,
             ocUpload,
             NameCollisionPolicy.DEFAULT,
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             targetContext,
             true,
             false,
@@ -400,7 +400,7 @@ public class UploadIT extends AbstractOnServerIT {
             null,
             ocUpload,
             NameCollisionPolicy.DEFAULT,
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             targetContext,
             true,
             false,
@@ -433,7 +433,7 @@ public class UploadIT extends AbstractOnServerIT {
                 null,
                 ocUpload,
                 NameCollisionPolicy.DEFAULT,
-                FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+                FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
                 targetContext,
                 false,
                 false,
@@ -480,18 +480,18 @@ public class UploadIT extends AbstractOnServerIT {
 
         assertTrue(
                 new UploadFileOperation(
-                        uploadsStorageManager,
-                        connectivityServiceMock,
-                        powerManagementServiceMock,
-                        user,
-                        null,
-                        ocUpload,
-                        NameCollisionPolicy.DEFAULT,
-                        FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
-                        targetContext,
-                        false,
-                        false,
-                        getStorageManager()
+                    uploadsStorageManager,
+                    connectivityServiceMock,
+                    powerManagementServiceMock,
+                    user,
+                    null,
+                    ocUpload,
+                    NameCollisionPolicy.DEFAULT,
+                    FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
+                    targetContext,
+                    false,
+                    false,
+                    getStorageManager()
                 )
                         .setRemoteFolderToBeCreated()
                         .execute(client)

+ 15 - 15
app/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt

@@ -26,7 +26,7 @@ import com.nextcloud.client.account.UserAccountManager
 import com.nextcloud.client.account.UserAccountManagerImpl
 import com.nextcloud.client.device.BatteryStatus
 import com.nextcloud.client.device.PowerManagementService
-import com.nextcloud.client.jobs.FilesUploadWorker
+import com.nextcloud.client.files.uploader.FileUploadWorker
 import com.nextcloud.client.network.Connectivity
 import com.nextcloud.client.network.ConnectivityService
 import com.owncloud.android.AbstractOnServerIT
@@ -144,7 +144,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
             user,
             arrayOf(file.absolutePath),
             arrayOf("/testFile.txt"),
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             true,
             UploadFileOperation.CREATED_BY_USER,
             false,
@@ -165,7 +165,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
         FilesUploadHelper().uploadUpdatedFile(
             user,
             arrayOf(ocFile2),
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             NameCollisionPolicy.OVERWRITE
         )
 
@@ -196,7 +196,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
                 null,
                 ocUpload,
                 NameCollisionPolicy.DEFAULT,
-                FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+                FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
                 targetContext,
                 false,
                 false,
@@ -224,7 +224,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
                 null,
                 ocUpload2,
                 NameCollisionPolicy.RENAME,
-                FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+                FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
                 targetContext,
                 false,
                 false,
@@ -260,7 +260,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
             user,
             arrayOf(file.absolutePath),
             arrayOf("/testFile.txt"),
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             true,
             UploadFileOperation.CREATED_BY_USER,
             false,
@@ -281,7 +281,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
         FilesUploadHelper().uploadUpdatedFile(
             user,
             arrayOf(ocFile2),
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             NameCollisionPolicy.RENAME
         )
 
@@ -315,7 +315,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
                 null,
                 ocUpload,
                 NameCollisionPolicy.DEFAULT,
-                FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+                FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
                 targetContext,
                 false,
                 false,
@@ -342,7 +342,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
                 null,
                 ocUpload2,
                 NameCollisionPolicy.CANCEL,
-                FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+                FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
                 targetContext,
                 false,
                 false,
@@ -368,7 +368,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
             user,
             arrayOf(file.absolutePath),
             arrayOf("/testFile.txt"),
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             true,
             UploadFileOperation.CREATED_BY_USER,
             false,
@@ -389,7 +389,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
         FilesUploadHelper().uploadUpdatedFile(
             user,
             arrayOf(ocFile2),
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             NameCollisionPolicy.CANCEL
         )
 
@@ -418,7 +418,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
                 null,
                 ocUpload,
                 NameCollisionPolicy.CANCEL,
-                FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+                FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
                 targetContext,
                 false,
                 false,
@@ -444,7 +444,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
             null,
             ocUpload2,
             NameCollisionPolicy.CANCEL,
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             targetContext,
             false,
             false,
@@ -472,7 +472,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
             user,
             arrayOf(file.absolutePath),
             arrayOf("/testFile.txt"),
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             true,
             UploadFileOperation.CREATED_BY_USER,
             false,
@@ -493,7 +493,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
         FilesUploadHelper().uploadUpdatedFile(
             user,
             arrayOf(ocFile2),
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             NameCollisionPolicy.CANCEL
         )
 

+ 2 - 2
app/src/androidTest/java/com/owncloud/android/ui/helpers/UriUploaderIT.kt

@@ -2,7 +2,7 @@ package com.owncloud.android.ui.helpers
 
 import android.net.Uri
 import androidx.test.core.app.launchActivity
-import com.nextcloud.client.jobs.FilesUploadWorker
+import com.nextcloud.client.files.uploader.FileUploadWorker
 import com.nextcloud.test.TestActivity
 import com.owncloud.android.AbstractIT
 import org.junit.Assert
@@ -38,7 +38,7 @@ class UriUploaderIT : AbstractIT() {
             listOf(Uri.parse(path)),
             "",
             activity.user.orElseThrow(::RuntimeException),
-            FilesUploadWorker.LOCAL_BEHAVIOUR_MOVE,
+            FileUploadWorker.LOCAL_BEHAVIOUR_MOVE,
             false,
             null
         )

+ 1 - 1
app/src/main/AndroidManifest.xml

@@ -170,7 +170,7 @@
             android:name="com.nextcloud.client.jobs.NotificationWork$NotificationReceiver"
             android:exported="false" />
         <receiver
-            android:name="com.nextcloud.client.jobs.FilesUploadWorker$Companion$UploadNotificationActionReceiver"
+            android:name="com.nextcloud.client.files.uploader.FileUploadWorker$Companion$UploadNotificationActionReceiver"
             android:exported="false" />
         <receiver
             android:name="com.nextcloud.client.widget.DashboardWidgetProvider"

+ 2 - 2
app/src/main/java/com/nextcloud/client/documentscan/DocumentScanViewModel.kt

@@ -29,8 +29,8 @@ import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.viewModelScope
 import com.nextcloud.client.account.CurrentAccountProvider
 import com.nextcloud.client.di.IoDispatcher
+import com.nextcloud.client.files.uploader.FileUploadWorker
 import com.nextcloud.client.jobs.BackgroundJobManager
-import com.nextcloud.client.jobs.FilesUploadWorker
 import com.nextcloud.client.logger.Logger
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.files.services.NameCollisionPolicy
@@ -188,7 +188,7 @@ class DocumentScanViewModel @Inject constructor(
             currentAccountProvider.user,
             pageList.toTypedArray(),
             uploadPaths,
-            FilesUploadWorker.LOCAL_BEHAVIOUR_DELETE,
+            FileUploadWorker.LOCAL_BEHAVIOUR_DELETE,
             true,
             UploadFileOperation.CREATED_BY_USER,
             false,

+ 2 - 2
app/src/main/java/com/nextcloud/client/documentscan/GeneratePdfFromImagesWork.kt

@@ -32,7 +32,7 @@ import androidx.work.WorkerParameters
 import com.nextcloud.client.account.AnonymousUser
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.UserAccountManager
-import com.nextcloud.client.jobs.FilesUploadWorker
+import com.nextcloud.client.files.uploader.FileUploadWorker
 import com.nextcloud.client.logger.Logger
 import com.owncloud.android.R
 import com.owncloud.android.datamodel.OCFile
@@ -127,7 +127,7 @@ class GeneratePdfFromImagesWork(
             user,
             arrayOf(pdfPath),
             arrayOf(uploadPath),
-            FilesUploadWorker.LOCAL_BEHAVIOUR_DELETE, // MIME type will be detected from file name
+            FileUploadWorker.LOCAL_BEHAVIOUR_DELETE, // MIME type will be detected from file name
             true,
             UploadFileOperation.CREATED_BY_USER,
             false,

+ 2 - 2
app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt

@@ -34,7 +34,7 @@ import androidx.core.view.WindowCompat
 import androidx.core.view.WindowInsetsCompat
 import com.canhub.cropper.CropImageView
 import com.nextcloud.client.di.Injectable
-import com.nextcloud.client.jobs.FilesUploadWorker
+import com.nextcloud.client.files.uploader.FileUploadWorker
 import com.nextcloud.utils.extensions.getParcelableArgument
 import com.owncloud.android.R
 import com.owncloud.android.databinding.ActivityEditImageBinding
@@ -121,7 +121,7 @@ class EditImageActivity :
                 requiresWifi = false,
                 requiresCharging = false,
                 nameCollisionPolicy = NameCollisionPolicy.RENAME,
-                localBehavior = FilesUploadWorker.LOCAL_BEHAVIOUR_DELETE
+                localBehavior = FileUploadWorker.LOCAL_BEHAVIOUR_DELETE
             )
         }
     }

+ 5 - 5
app/src/main/java/com/nextcloud/client/files/upload/PostUploadAction.kt

@@ -19,11 +19,11 @@
  */
 package com.nextcloud.client.files.upload
 
-import com.nextcloud.client.jobs.FilesUploadWorker
+import com.nextcloud.client.files.uploader.FileUploadWorker
 
 enum class PostUploadAction(val value: Int) {
-    NONE(FilesUploadWorker.LOCAL_BEHAVIOUR_FORGET),
-    COPY_TO_APP(FilesUploadWorker.LOCAL_BEHAVIOUR_COPY),
-    MOVE_TO_APP(FilesUploadWorker.LOCAL_BEHAVIOUR_MOVE),
-    DELETE_SOURCE(FilesUploadWorker.LOCAL_BEHAVIOUR_DELETE)
+    NONE(FileUploadWorker.LOCAL_BEHAVIOUR_FORGET),
+    COPY_TO_APP(FileUploadWorker.LOCAL_BEHAVIOUR_COPY),
+    MOVE_TO_APP(FileUploadWorker.LOCAL_BEHAVIOUR_MOVE),
+    DELETE_SOURCE(FileUploadWorker.LOCAL_BEHAVIOUR_DELETE)
 }

+ 77 - 68
app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt → app/src/main/java/com/nextcloud/client/files/uploader/FileUploadWorker.kt

@@ -1,10 +1,9 @@
 /*
- *
  * Nextcloud Android client application
  *
- * @author Tobias Kaminsky
- * Copyright (C) 2022 Tobias Kaminsky
- * Copyright (C) 2022 Nextcloud GmbH
+ * @author Alper Ozturk
+ * Copyright (C) 2023 Alper Ozturk
+ * Copyright (C) 2023 Nextcloud GmbH
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -20,7 +19,7 @@
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
  */
 
-package com.nextcloud.client.jobs
+package com.nextcloud.client.files.uploader
 
 import android.content.BroadcastReceiver
 import android.content.Context
@@ -31,10 +30,9 @@ import androidx.work.WorkerParameters
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.UserAccountManager
 import com.nextcloud.client.device.PowerManagementService
-import com.nextcloud.client.files.uploader.FileUploaderIntents
-import com.nextcloud.client.files.uploader.UploadNotificationManager
+import com.nextcloud.client.jobs.BackgroundJobManager
+import com.nextcloud.client.jobs.BackgroundJobManagerImpl
 import com.nextcloud.client.network.ConnectivityService
-import com.nextcloud.client.utils.FileUploaderDelegate
 import com.nextcloud.java.util.Optional
 import com.owncloud.android.R
 import com.owncloud.android.datamodel.FileDataStorageManager
@@ -55,7 +53,7 @@ import com.owncloud.android.utils.theme.ViewThemeUtils
 import java.io.File
 
 @Suppress("LongParameterList")
-class FilesUploadWorker(
+class FileUploadWorker(
     val uploadsStorageManager: UploadsStorageManager,
     val connectivityService: ConnectivityService,
     val powerManagementService: PowerManagementService,
@@ -81,13 +79,17 @@ class FilesUploadWorker(
 
             val result = Result.failure()
             backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
-            return result // user account is needed
+            return result
         }
 
-        /*
-         * As pages are retrieved by sorting uploads by ID, if new uploads are added while uploading the current ones,
-         * they will be present in the pages that follow.
-         */
+        retrievePagesBySortingUploadsByID(accountName)
+
+        val result = Result.success()
+        backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
+        return result
+    }
+
+    private fun retrievePagesBySortingUploadsByID(accountName: String) {
         var currentPage = uploadsStorageManager.getCurrentAndPendingUploadsForAccountPageAscById(-1, accountName)
         while (currentPage.isNotEmpty() && !isStopped) {
             Log_OC.d(TAG, "Handling ${currentPage.size} uploads for account $accountName")
@@ -98,19 +100,15 @@ class FilesUploadWorker(
         }
 
         Log_OC.d(TAG, "No more pending uploads for account $accountName, stopping work")
-        val result = Result.success()
-        backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
-        return result
     }
 
     private fun handlePendingUploads(uploads: List<OCUpload>, accountName: String) {
         val user = userAccountManager.getUser(accountName)
-
         for (upload in uploads) {
             if (isStopped) {
                 break
             }
-            // create upload file operation
+
             if (user.isPresent) {
                 val uploadFileOperation = createUploadFileOperation(upload, user.get())
 
@@ -126,7 +124,6 @@ class FilesUploadWorker(
                     localBroadcastManager
                 )
             } else {
-                // user not present anymore, remove upload
                 uploadsStorageManager.removeUpload(upload.uploadId)
             }
         }
@@ -148,7 +145,7 @@ class FilesUploadWorker(
             true,
             FileDataStorageManager(user, context.contentResolver)
         ).apply {
-            addDataTransferProgressListener(this@FilesUploadWorker)
+            addDataTransferProgressListener(this@FileUploadWorker)
         }
     }
 
@@ -175,13 +172,9 @@ class FilesUploadWorker(
             Log_OC.e(TAG, "Error uploading", e)
             uploadResult = RemoteOperationResult<Any?>(e)
         } finally {
-            // only update db if operation finished and worker didn't get canceled
             if (!(isStopped && uploadResult.isCancelled)) {
                 uploadsStorageManager.updateDatabaseUploadResult(uploadResult, uploadFileOperation)
-
-                // / notify result
                 notifyUploadResult(uploadFileOperation, uploadResult)
-
                 notificationManager.dismissWorkerNotifications()
             }
         }
@@ -200,36 +193,32 @@ class FilesUploadWorker(
             return
         }
 
-        // Only notify if the upload fails
         if (uploadResult.isCancelled) {
             return
         }
 
-        val notDelayed = uploadResult.code != ResultCode.DELAYED_FOR_WIFI &&
-            uploadResult.code != ResultCode.DELAYED_FOR_CHARGING &&
-            uploadResult.code != ResultCode.DELAYED_IN_POWER_SAVE_MODE
+        val notDelayed = uploadResult.code !in setOf(
+            ResultCode.DELAYED_FOR_WIFI,
+            ResultCode.DELAYED_FOR_CHARGING,
+            ResultCode.DELAYED_IN_POWER_SAVE_MODE
+        )
 
-        if (notDelayed &&
-            uploadResult.code != ResultCode.LOCAL_FILE_NOT_FOUND &&
-            uploadResult.code != ResultCode.LOCK_FAILED
-        ) {
-            var tickerId = R.string.uploader_upload_failed_ticker
+        val isValidFile = uploadResult.code !in setOf(
+            ResultCode.LOCAL_FILE_NOT_FOUND,
+            ResultCode.LOCK_FAILED,
+        )
 
-            // check credentials error
-            val needsToUpdateCredentials = uploadResult.code == ResultCode.UNAUTHORIZED
-            if (needsToUpdateCredentials) {
-                tickerId = R.string.uploader_upload_failed_credentials_error
-            } else if (uploadResult.code == ResultCode.SYNC_CONFLICT) {
-                // check file conflict
-                tickerId = R.string.uploader_upload_failed_sync_conflict_error
-            }
-            notificationManager.notifyForResult(tickerId)
+        if (!notDelayed || !isValidFile) {
+            return
+        }
 
-            val content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, uploadFileOperation, context.resources)
-            notificationManager.setContentIntent(intents.resultIntent(ResultCode.OK, uploadFileOperation))
+        val (tickerId, needsToUpdateCredentials) = getTickerId(uploadResult.code)
+        notificationManager.run {
+            notifyForResult(tickerId)
+            setContentIntent(intents.resultIntent(ResultCode.OK, uploadFileOperation))
 
             if (uploadResult.code == ResultCode.SYNC_CONFLICT) {
-                notificationManager.addAction(
+                addAction(
                     R.drawable.ic_cloud_upload,
                     R.string.upload_list_resolve_conflict,
                     intents.conflictResolveActionIntents(context, uploadFileOperation)
@@ -237,19 +226,34 @@ class FilesUploadWorker(
             }
 
             if (needsToUpdateCredentials) {
-                notificationManager.setContentIntent(intents.credentialIntent(uploadFileOperation))
+                setContentIntent(intents.credentialIntent(uploadFileOperation))
             }
 
-            notificationManager.setContentText(content)
+            val content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, uploadFileOperation, context.resources)
+            setContentText(content)
 
             if (!uploadResult.isSuccess) {
-                notificationManager.showRandomNotification()
+                showRandomNotification()
             }
 
-            notificationManager.showNotificationTag(uploadFileOperation)
+            showNotificationTag(uploadFileOperation)
         }
     }
 
+    private fun getTickerId(resultCode: ResultCode): Pair<Int, Boolean> {
+        var tickerId = R.string.uploader_upload_failed_ticker
+
+        val needsToUpdateCredentials = (resultCode == ResultCode.UNAUTHORIZED)
+
+        if (needsToUpdateCredentials) {
+            tickerId = R.string.uploader_upload_failed_credentials_error
+        } else if (resultCode == ResultCode.SYNC_CONFLICT) {
+            tickerId = R.string.uploader_upload_failed_sync_conflict_error
+        }
+
+        return Pair(tickerId, needsToUpdateCredentials)
+    }
+
     override fun onTransferProgress(
         progressRate: Long,
         totalTransferredSoFar: Long,
@@ -259,14 +263,23 @@ class FilesUploadWorker(
         val percent = (MAX_PROGRESS * totalTransferredSoFar.toDouble() / totalToTransfer.toDouble()).toInt()
         if (percent != lastPercent) {
             notificationManager.updateUploadProgressNotification(fileAbsoluteName, percent, currentUploadFileOperation)
-            FilesUploadHelper.onTransferProgress(
-                currentUploadFileOperation?.user?.accountName,
-                currentUploadFileOperation?.remotePath,
-                progressRate,
-                totalTransferredSoFar,
-                totalToTransfer,
-                fileAbsoluteName
-            )
+
+            val accountName = currentUploadFileOperation?.user?.accountName
+            val remotePath = currentUploadFileOperation?.remotePath
+
+            if (accountName != null && remotePath != null) {
+                val key: String =
+                    FilesUploadHelper.buildRemoteName(accountName, remotePath)
+                val boundListener = FilesUploadHelper.mBoundListeners[key]
+
+                boundListener?.onTransferProgress(
+                    progressRate,
+                    totalTransferredSoFar,
+                    totalToTransfer,
+                    fileAbsoluteName
+                )
+            }
+
             notificationManager.dismissOldErrorNotification(currentUploadFileOperation)
         }
         lastPercent = percent
@@ -279,7 +292,7 @@ class FilesUploadWorker(
     }
 
     companion object {
-        val TAG: String = FilesUploadWorker::class.java.simpleName
+        val TAG: String = FileUploadWorker::class.java.simpleName
 
         const val NOTIFICATION_ERROR_ID: Int = 413
         private const val MAX_PROGRESS: Int = 100
@@ -298,7 +311,6 @@ class FilesUploadWorker(
         const val ACCOUNT_NAME = "ACCOUNT_NAME"
         const val EXTRA_ACCOUNT_NAME = "ACCOUNT_NAME"
         const val ACTION_CANCEL_BROADCAST = "CANCEL"
-        const val ACTION_PAUSE_BROADCAST = "PAUSE"
         const val LOCAL_BEHAVIOUR_COPY = 0
         const val LOCAL_BEHAVIOUR_MOVE = 1
         const val LOCAL_BEHAVIOUR_FORGET = 2
@@ -306,7 +318,6 @@ class FilesUploadWorker(
 
         @Suppress("ComplexCondition")
         fun retryFailedUploads(
-            context: Context,
             uploadsStorageManager: UploadsStorageManager,
             connectivityService: ConnectivityService,
             accountManager: UserAccountManager,
@@ -351,23 +362,23 @@ class FilesUploadWorker(
         }
 
         fun getUploadsAddedMessage(): String {
-            return FilesUploadWorker::class.java.name + UPLOADS_ADDED_MESSAGE
+            return FileUploadWorker::class.java.name + UPLOADS_ADDED_MESSAGE
         }
 
         fun getUploadStartMessage(): String {
-            return FilesUploadWorker::class.java.name + UPLOAD_START_MESSAGE
+            return FileUploadWorker::class.java.name + UPLOAD_START_MESSAGE
         }
 
         fun getUploadFinishMessage(): String {
-            return FilesUploadWorker::class.java.name + UPLOAD_FINISH_MESSAGE
+            return FileUploadWorker::class.java.name + UPLOAD_FINISH_MESSAGE
         }
 
-        @Suppress("EmptyIfBlock")
         class UploadNotificationActionReceiver : BroadcastReceiver() {
             override fun onReceive(context: Context, intent: Intent) {
                 val accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME)
                 val remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH)
                 val action = intent.action
+
                 if (ACTION_CANCEL_BROADCAST == action) {
                     Log_OC.d(
                         TAG,
@@ -376,11 +387,9 @@ class FilesUploadWorker(
                     if (accountName == null || remotePath == null) {
                         return
                     }
+
                     val uploadHelper = FilesUploadHelper()
                     uploadHelper.cancelFileUpload(remotePath, accountName)
-                } else if (ACTION_PAUSE_BROADCAST == action) {
-                } else {
-                    Log_OC.d(TAG, "Unknown action to perform as UploadNotificationActionReceiver.")
                 }
             }
         }

+ 16 - 18
app/src/main/java/com/nextcloud/client/utils/FileUploaderDelegate.kt → app/src/main/java/com/nextcloud/client/files/uploader/FileUploaderDelegate.kt

@@ -1,10 +1,9 @@
 /*
- *
  * Nextcloud Android client application
  *
- * @author Tobias Kaminsky
- * Copyright (C) 2022 Tobias Kaminsky
- * Copyright (C) 2022 Nextcloud GmbH
+ * @author Alper Ozturk
+ * Copyright (C) 2023 Alper Ozturk
+ * Copyright (C) 2023 Nextcloud GmbH
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -20,12 +19,11 @@
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
  */
 
-package com.nextcloud.client.utils
+package com.nextcloud.client.files.uploader
 
 import android.content.Context
 import android.content.Intent
 import androidx.localbroadcastmanager.content.LocalBroadcastManager
-import com.nextcloud.client.jobs.FilesUploadWorker
 import com.owncloud.android.lib.common.operations.RemoteOperationResult
 import com.owncloud.android.operations.UploadFileOperation
 
@@ -36,7 +34,7 @@ class FileUploaderDelegate {
      * TODO - no more broadcasts, replace with a callback to subscribed listeners once we drop FileUploader
      */
     fun sendBroadcastUploadsAdded(context: Context, localBroadcastManager: LocalBroadcastManager) {
-        val start = Intent(FilesUploadWorker.getUploadsAddedMessage())
+        val start = Intent(FileUploadWorker.getUploadsAddedMessage())
         // nothing else needed right now
         start.setPackage(context.packageName)
         localBroadcastManager.sendBroadcast(start)
@@ -54,10 +52,10 @@ class FileUploaderDelegate {
         context: Context,
         localBroadcastManager: LocalBroadcastManager
     ) {
-        val start = Intent(FilesUploadWorker.getUploadStartMessage())
-        start.putExtra(FilesUploadWorker.EXTRA_REMOTE_PATH, upload.remotePath) // real remote
-        start.putExtra(FilesUploadWorker.EXTRA_OLD_FILE_PATH, upload.originalStoragePath)
-        start.putExtra(FilesUploadWorker.ACCOUNT_NAME, upload.user.accountName)
+        val start = Intent(FileUploadWorker.getUploadStartMessage())
+        start.putExtra(FileUploadWorker.EXTRA_REMOTE_PATH, upload.remotePath) // real remote
+        start.putExtra(FileUploadWorker.EXTRA_OLD_FILE_PATH, upload.originalStoragePath)
+        start.putExtra(FileUploadWorker.ACCOUNT_NAME, upload.user.accountName)
         start.setPackage(context.packageName)
         localBroadcastManager.sendBroadcast(start)
     }
@@ -78,17 +76,17 @@ class FileUploaderDelegate {
         context: Context,
         localBroadcastManager: LocalBroadcastManager
     ) {
-        val end = Intent(FilesUploadWorker.getUploadFinishMessage())
+        val end = Intent(FileUploadWorker.getUploadFinishMessage())
         // real remote path, after possible automatic renaming
-        end.putExtra(FilesUploadWorker.EXTRA_REMOTE_PATH, upload.remotePath)
+        end.putExtra(FileUploadWorker.EXTRA_REMOTE_PATH, upload.remotePath)
         if (upload.wasRenamed()) {
-            end.putExtra(FilesUploadWorker.EXTRA_OLD_REMOTE_PATH, upload.oldFile!!.remotePath)
+            end.putExtra(FileUploadWorker.EXTRA_OLD_REMOTE_PATH, upload.oldFile!!.remotePath)
         }
-        end.putExtra(FilesUploadWorker.EXTRA_OLD_FILE_PATH, upload.originalStoragePath)
-        end.putExtra(FilesUploadWorker.ACCOUNT_NAME, upload.user.accountName)
-        end.putExtra(FilesUploadWorker.EXTRA_UPLOAD_RESULT, uploadResult.isSuccess)
+        end.putExtra(FileUploadWorker.EXTRA_OLD_FILE_PATH, upload.originalStoragePath)
+        end.putExtra(FileUploadWorker.ACCOUNT_NAME, upload.user.accountName)
+        end.putExtra(FileUploadWorker.EXTRA_UPLOAD_RESULT, uploadResult.isSuccess)
         if (unlinkedFromRemotePath != null) {
-            end.putExtra(FilesUploadWorker.EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath)
+            end.putExtra(FileUploadWorker.EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath)
         }
         end.setPackage(context.packageName)
         localBroadcastManager.sendBroadcast(end)

+ 4 - 5
app/src/main/java/com/nextcloud/client/files/uploader/FileUploaderIntents.kt

@@ -25,7 +25,6 @@ import android.app.PendingIntent
 import android.content.Context
 import android.content.Intent
 import android.os.Build
-import com.nextcloud.client.jobs.FilesUploadWorker
 import com.owncloud.android.authentication.AuthenticatorActivity
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
 import com.owncloud.android.operations.UploadFileOperation
@@ -40,11 +39,11 @@ class FileUploaderIntents(private val context: Context) {
     fun startIntent(operation: UploadFileOperation): PendingIntent {
         val intent = Intent(
             context,
-            FilesUploadWorker.Companion.UploadNotificationActionReceiver::class.java
+            FileUploadWorker.Companion.UploadNotificationActionReceiver::class.java
         ).apply {
-            putExtra(FilesUploadWorker.EXTRA_ACCOUNT_NAME, operation.user.accountName)
-            putExtra(FilesUploadWorker.EXTRA_REMOTE_PATH, operation.remotePath)
-            action = FilesUploadWorker.ACTION_CANCEL_BROADCAST
+            putExtra(FileUploadWorker.EXTRA_ACCOUNT_NAME, operation.user.accountName)
+            putExtra(FileUploadWorker.EXTRA_REMOTE_PATH, operation.remotePath)
+            action = FileUploadWorker.ACTION_CANCEL_BROADCAST
         }
 
         return PendingIntent.getBroadcast(

+ 3 - 4
app/src/main/java/com/nextcloud/client/files/uploader/UploadNotificationManager.kt

@@ -29,7 +29,6 @@ import android.content.Intent
 import android.graphics.BitmapFactory
 import android.os.Build
 import androidx.core.app.NotificationCompat
-import com.nextcloud.client.jobs.FilesUploadWorker
 import com.owncloud.android.R
 import com.owncloud.android.lib.resources.files.FileUtils
 import com.owncloud.android.operations.UploadFileOperation
@@ -145,7 +144,7 @@ class UploadNotificationManager(private val context: Context, private val viewTh
     fun showNotificationTag(operation: UploadFileOperation) {
         notificationManager.notify(
             NotificationUtils.createUploadNotificationTag(operation.file),
-            FilesUploadWorker.NOTIFICATION_ERROR_ID,
+            FileUploadWorker.NOTIFICATION_ERROR_ID,
             notificationBuilder.build()
         )
     }
@@ -177,13 +176,13 @@ class UploadNotificationManager(private val context: Context, private val viewTh
 
         notificationManager.cancel(
             NotificationUtils.createUploadNotificationTag(operation.file),
-            FilesUploadWorker.NOTIFICATION_ERROR_ID
+            FileUploadWorker.NOTIFICATION_ERROR_ID
         )
 
         operation.oldFile?.let {
             notificationManager.cancel(
                 NotificationUtils.createUploadNotificationTag(it),
-                FilesUploadWorker.NOTIFICATION_ERROR_ID
+                FileUploadWorker.NOTIFICATION_ERROR_ID
             )
         }
     }

+ 5 - 4
app/src/main/java/com/nextcloud/client/jobs/BackgroundJobFactory.kt

@@ -34,8 +34,9 @@ import com.nextcloud.client.device.DeviceInfo
 import com.nextcloud.client.device.PowerManagementService
 import com.nextcloud.client.documentscan.GeneratePDFUseCase
 import com.nextcloud.client.documentscan.GeneratePdfFromImagesWork
-import com.nextcloud.client.files.downloader.FileDownloadWorker
 import com.nextcloud.client.integrations.deck.DeckApi
+import com.nextcloud.client.jobs.download.FileDownloadWorker
+import com.nextcloud.client.jobs.upload.FileUploadWorker
 import com.nextcloud.client.logger.Logger
 import com.nextcloud.client.network.ConnectivityService
 import com.nextcloud.client.preferences.AppPreferences
@@ -102,7 +103,7 @@ class BackgroundJobFactory @Inject constructor(
                 CalendarBackupWork::class -> createCalendarBackupWork(context, workerParameters)
                 CalendarImportWork::class -> createCalendarImportWork(context, workerParameters)
                 FilesExportWork::class -> createFilesExportWork(context, workerParameters)
-                FilesUploadWorker::class -> createFilesUploadWorker(context, workerParameters)
+                FileUploadWorker::class -> createFilesUploadWorker(context, workerParameters)
                 FileDownloadWorker::class -> createFilesDownloadWorker(context, workerParameters)
                 GeneratePdfFromImagesWork::class -> createPDFGenerateWork(context, workerParameters)
                 HealthStatusWork::class -> createHealthStatusWork(context, workerParameters)
@@ -241,8 +242,8 @@ class BackgroundJobFactory @Inject constructor(
         )
     }
 
-    private fun createFilesUploadWorker(context: Context, params: WorkerParameters): FilesUploadWorker {
-        return FilesUploadWorker(
+    private fun createFilesUploadWorker(context: Context, params: WorkerParameters): FileUploadWorker {
+        return FileUploadWorker(
             uploadsStorageManager,
             connectivityService,
             powerManagementService,

+ 17 - 4
app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt

@@ -38,7 +38,8 @@ import com.nextcloud.client.account.User
 import com.nextcloud.client.core.Clock
 import com.nextcloud.client.di.Injectable
 import com.nextcloud.client.documentscan.GeneratePdfFromImagesWork
-import com.nextcloud.client.files.downloader.FileDownloadWorker
+import com.nextcloud.client.jobs.download.FileDownloadWorker
+import com.nextcloud.client.jobs.upload.FileUploadWorker
 import com.nextcloud.client.preferences.AppPreferences
 import com.nextcloud.utils.extensions.isWorkScheduled
 import com.owncloud.android.datamodel.OCFile
@@ -499,14 +500,26 @@ internal class BackgroundJobManagerImpl(
 
         workManager.enqueue(request)
     }
+
+    private fun startFileUploadJobTag(user: User): String {
+        return JOB_FILES_UPLOAD + user.accountName
+    }
+
+    override fun isStartFileUploadJobScheduled(user: User): Boolean {
+        return workManager.isWorkScheduled(startFileUploadJobTag(user))
+    }
+
     override fun startFilesUploadJob(user: User) {
-        val data = workDataOf(FilesUploadWorker.ACCOUNT to user.accountName)
+        val data = workDataOf(FileUploadWorker.ACCOUNT to user.accountName)
+
+        val tag = startFileUploadJobTag(user)
 
-        val request = oneTimeRequestBuilder(FilesUploadWorker::class, JOB_FILES_UPLOAD, user)
+        val request = oneTimeRequestBuilder(FileUploadWorker::class, JOB_FILES_UPLOAD, user)
+            .addTag(tag)
             .setInputData(data)
             .build()
 
-        workManager.enqueueUniqueWork(JOB_FILES_UPLOAD + user.accountName, ExistingWorkPolicy.KEEP, request)
+        workManager.enqueueUniqueWork(tag, ExistingWorkPolicy.KEEP, request)
     }
 
     private fun startFileDownloadJobTag(user: User, fileId: Long): String {

+ 5 - 4
app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt

@@ -34,6 +34,7 @@ import androidx.work.ForegroundInfo
 import androidx.work.WorkerParameters
 import com.nextcloud.client.account.UserAccountManager
 import com.nextcloud.client.device.PowerManagementService
+import com.nextcloud.client.files.uploader.FileUploadWorker
 import com.nextcloud.client.network.ConnectivityService
 import com.nextcloud.client.preferences.SubFolderRule
 import com.owncloud.android.R
@@ -292,10 +293,10 @@ class FilesSyncWork(
 
     private fun getUploadAction(action: String): Int? {
         return when (action) {
-            "LOCAL_BEHAVIOUR_FORGET" -> FilesUploadWorker.LOCAL_BEHAVIOUR_FORGET
-            "LOCAL_BEHAVIOUR_MOVE" -> FilesUploadWorker.LOCAL_BEHAVIOUR_MOVE
-            "LOCAL_BEHAVIOUR_DELETE" -> FilesUploadWorker.LOCAL_BEHAVIOUR_DELETE
-            else -> FilesUploadWorker.LOCAL_BEHAVIOUR_FORGET
+            "LOCAL_BEHAVIOUR_FORGET" -> FileUploadWorker.LOCAL_BEHAVIOUR_FORGET
+            "LOCAL_BEHAVIOUR_MOVE" -> FileUploadWorker.LOCAL_BEHAVIOUR_MOVE
+            "LOCAL_BEHAVIOUR_DELETE" -> FileUploadWorker.LOCAL_BEHAVIOUR_DELETE
+            else -> FileUploadWorker.LOCAL_BEHAVIOUR_FORGET
         }
     }
 }

+ 27 - 0
app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt

@@ -27,7 +27,12 @@ import android.content.Context
 import android.content.Intent
 import android.content.IntentFilter
 import android.os.Build
+import androidx.work.WorkInfo
+import androidx.work.WorkManager
+import com.google.common.util.concurrent.ListenableFuture
 import com.owncloud.android.datamodel.ReceiverFlag
+import com.owncloud.android.lib.common.utils.Log_OC
+import java.util.concurrent.ExecutionException
 
 @SuppressLint("UnspecifiedRegisterReceiverFlag")
 fun Context.registerBroadcastReceiver(receiver: BroadcastReceiver?, filter: IntentFilter, flag: ReceiverFlag): Intent? {
@@ -37,3 +42,25 @@ fun Context.registerBroadcastReceiver(receiver: BroadcastReceiver?, filter: Inte
         registerReceiver(receiver, filter)
     }
 }
+
+fun Context.isWorkScheduled(tag: String): Boolean {
+    val instance = WorkManager.getInstance(this)
+    val statuses: ListenableFuture<List<WorkInfo>> = instance.getWorkInfosByTag(tag)
+    var running = false
+    var workInfoList: List<WorkInfo> = emptyList()
+
+    try {
+        workInfoList = statuses.get()
+    } catch (e: ExecutionException) {
+        Log_OC.d("Worker", "ExecutionException in isWorkScheduled: $e")
+    } catch (e: InterruptedException) {
+        Log_OC.d("Worker", "InterruptedException in isWorkScheduled: $e")
+    }
+
+    for (workInfo in workInfoList) {
+        val state = workInfo.state
+        running = running || (state == WorkInfo.State.RUNNING || state == WorkInfo.State.ENQUEUED)
+    }
+
+    return running
+}

+ 2 - 2
app/src/main/java/com/owncloud/android/db/OCUpload.java

@@ -27,7 +27,7 @@ import android.os.Parcel;
 import android.os.Parcelable;
 
 import com.nextcloud.client.account.User;
-import com.nextcloud.client.jobs.FilesUploadWorker;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus;
@@ -172,7 +172,7 @@ public class OCUpload implements Parcelable {
         accountName = "";
         fileSize = -1;
         uploadId = -1;
-        localAction = FilesUploadWorker.LOCAL_BEHAVIOUR_COPY;
+        localAction = FileUploadWorker.LOCAL_BEHAVIOUR_COPY;
         nameCollisionPolicy = NameCollisionPolicy.DEFAULT;
         createRemoteFolder = false;
         uploadStatus = UploadStatus.UPLOAD_IN_PROGRESS;

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

@@ -29,7 +29,7 @@ import android.text.TextUtils;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.device.BatteryStatus;
 import com.nextcloud.client.device.PowerManagementService;
-import com.nextcloud.client.jobs.FilesUploadWorker;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.nextcloud.client.network.Connectivity;
 import com.nextcloud.client.network.ConnectivityService;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
@@ -1019,7 +1019,7 @@ public class UploadFileOperation extends SyncOperation {
 
     private RemoteOperationResult copyFile(File originalFile, String expectedPath) throws OperationCancelledException,
         IOException {
-        if (mLocalBehaviour == FilesUploadWorker.LOCAL_BEHAVIOUR_COPY && !mOriginalStoragePath.equals(expectedPath)) {
+        if (mLocalBehaviour == FileUploadWorker.LOCAL_BEHAVIOUR_COPY && !mOriginalStoragePath.equals(expectedPath)) {
             String temporalPath = FileStorageUtils.getInternalTemporalPath(user.getAccountName(), mContext) +
                 mFile.getRemotePath();
             mFile.setStoragePath(temporalPath);
@@ -1077,20 +1077,20 @@ public class UploadFileOperation extends SyncOperation {
                                         File originalFile,
                                         OwnCloudClient client) {
         switch (mLocalBehaviour) {
-            case FilesUploadWorker.LOCAL_BEHAVIOUR_FORGET:
+            case FileUploadWorker.LOCAL_BEHAVIOUR_FORGET:
             default:
                 mFile.setStoragePath("");
                 saveUploadedFile(client);
                 break;
 
-            case FilesUploadWorker.LOCAL_BEHAVIOUR_DELETE:
+            case FileUploadWorker.LOCAL_BEHAVIOUR_DELETE:
                 originalFile.delete();
                 mFile.setStoragePath("");
                 getStorageManager().deleteFileInMediaScan(originalFile.getAbsolutePath());
                 saveUploadedFile(client);
                 break;
 
-            case FilesUploadWorker.LOCAL_BEHAVIOUR_COPY:
+            case FileUploadWorker.LOCAL_BEHAVIOUR_COPY:
                 if (temporalFile != null) {
                     try {
                         move(temporalFile, expectedFile);
@@ -1111,7 +1111,7 @@ public class UploadFileOperation extends SyncOperation {
                 }
                 break;
 
-            case FilesUploadWorker.LOCAL_BEHAVIOUR_MOVE:
+            case FileUploadWorker.LOCAL_BEHAVIOUR_MOVE:
                 String expectedPath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), mFile);
                 File newFile = new File(expectedPath);
 

+ 3 - 3
app/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java

@@ -59,7 +59,7 @@ import android.widget.Toast;
 import com.google.android.material.button.MaterialButton;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.di.Injectable;
-import com.nextcloud.client.jobs.FilesUploadWorker;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.utils.extensions.BundleExtensionsKt;
 import com.nextcloud.utils.extensions.IntentExtensionsKt;
@@ -889,7 +889,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
             getUser().orElseThrow(RuntimeException::new),
             new String[]{ tmpName },
             new String[]{ mFile.getRemotePath() + filename},
-            FilesUploadWorker.LOCAL_BEHAVIOUR_COPY,
+            FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
             true,
             UploadFileOperation.CREATED_BY_USER,
             false,
@@ -906,7 +906,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
             mStreamsToUpload,
             mUploadPath,
             getUser().orElseThrow(RuntimeException::new),
-            FilesUploadWorker.LOCAL_BEHAVIOUR_DELETE,
+            FileUploadWorker.LOCAL_BEHAVIOUR_DELETE,
             true, // Show waiting dialog while file is being copied from private storage
             this  // Copy temp task listener
         );

+ 3 - 3
app/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.kt

@@ -40,8 +40,8 @@ import androidx.recyclerview.widget.GridLayoutManager
 import com.nextcloud.client.core.Clock
 import com.nextcloud.client.device.PowerManagementService
 import com.nextcloud.client.di.Injectable
+import com.nextcloud.client.files.uploader.FileUploadWorker
 import com.nextcloud.client.jobs.BackgroundJobManager
-import com.nextcloud.client.jobs.FilesUploadWorker
 import com.nextcloud.client.jobs.MediaFoldersDetectionWork
 import com.nextcloud.client.jobs.NotificationWork
 import com.nextcloud.client.preferences.AppPreferences
@@ -453,7 +453,7 @@ class SyncedFoldersActivity :
             true,
             false,
             account.name,
-            FilesUploadWorker.LOCAL_BEHAVIOUR_FORGET,
+            FileUploadWorker.LOCAL_BEHAVIOUR_FORGET,
             NameCollisionPolicy.ASK_USER.serialize(),
             false,
             clock.currentTime,
@@ -547,7 +547,7 @@ class SyncedFoldersActivity :
                         true,
                         false,
                         account.name,
-                        FilesUploadWorker.LOCAL_BEHAVIOUR_FORGET,
+                        FileUploadWorker.LOCAL_BEHAVIOUR_FORGET,
                         NameCollisionPolicy.ASK_USER.serialize(),
                         false,
                         clock.currentTime,

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

@@ -37,7 +37,7 @@ import android.widget.TextView;
 
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.di.Injectable;
-import com.nextcloud.client.jobs.FilesUploadWorker;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.owncloud.android.R;
 import com.owncloud.android.databinding.UploadFilesLayoutBinding;
@@ -499,7 +499,7 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList
                 data.putExtra(EXTRA_CHOSEN_FILES, new String[]{filesToUpload[0]});
                 setResult(RESULT_OK_AND_DELETE, data);
 
-                preferences.setUploaderBehaviour(FilesUploadWorker.LOCAL_BEHAVIOUR_DELETE);
+                preferences.setUploaderBehaviour(FileUploadWorker.LOCAL_BEHAVIOUR_DELETE);
             } else {
                 data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
                 data.putExtra(LOCAL_BASE_PATH, mCurrentDir.getAbsolutePath());

+ 5 - 7
app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java

@@ -38,8 +38,8 @@ import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.core.Clock;
 import com.nextcloud.client.device.PowerManagementService;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.nextcloud.client.jobs.BackgroundJobManager;
-import com.nextcloud.client.jobs.FilesUploadWorker;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.client.utils.Throttler;
 import com.owncloud.android.R;
@@ -194,9 +194,7 @@ public class UploadListActivity extends FileActivity {
         backgroundJobManager.startImmediateFilesSyncJob(false, true);
 
         if(uploadsStorageManager.getFailedUploads().length > 0){
-            // retry failed uploads
-            new Thread(() -> FilesUploadWorker.Companion.retryFailedUploads(
-                this,
+            new Thread(() -> FileUploadWorker.Companion.retryFailedUploads(
                 uploadsStorageManager,
                 connectivityService,
                 userAccountManager,
@@ -226,9 +224,9 @@ public class UploadListActivity extends FileActivity {
         // Listen for upload messages
         uploadMessagesReceiver = new UploadMessagesReceiver();
         IntentFilter uploadIntentFilter = new IntentFilter();
-        uploadIntentFilter.addAction(FilesUploadWorker.Companion.getUploadsAddedMessage());
-        uploadIntentFilter.addAction(FilesUploadWorker.Companion.getUploadStartMessage());
-        uploadIntentFilter.addAction(FilesUploadWorker.Companion.getUploadFinishMessage());
+        uploadIntentFilter.addAction(FileUploadWorker.Companion.getUploadsAddedMessage());
+        uploadIntentFilter.addAction(FileUploadWorker.Companion.getUploadStartMessage());
+        uploadIntentFilter.addAction(FileUploadWorker.Companion.getUploadFinishMessage());
         localBroadcastManager.registerReceiver(uploadMessagesReceiver, uploadIntentFilter);
 
         Log_OC.v(TAG, "onResume() end");

+ 4 - 4
app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java

@@ -43,7 +43,7 @@ import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.core.Clock;
 import com.nextcloud.client.device.PowerManagementService;
-import com.nextcloud.client.jobs.FilesUploadWorker;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.java.util.Optional;
 import com.owncloud.android.MainApp;
@@ -133,8 +133,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                     }
                 }
                 case FINISHED -> uploadsStorageManager.clearSuccessfulUploads();
-                case FAILED -> new Thread(() -> FilesUploadWorker.Companion.retryFailedUploads(
-                    parentActivity,
+                case FAILED -> new Thread(() -> FileUploadWorker.Companion.retryFailedUploads(
                     uploadsStorageManager,
                     connectivityService,
                     accountManager,
@@ -162,6 +161,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                              final Clock clock,
                              final ViewThemeUtils viewThemeUtils) {
         Log_OC.d(TAG, "UploadListAdapter");
+
         this.parentActivity = fileActivity;
         this.uploadsStorageManager = uploadsStorageManager;
         this.storageManager = storageManager;
@@ -883,7 +883,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
 
         if (upload == null) return;
         mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(upload.getRemotePath(),upload.getLocalPath()),
-                                    FilesUploadWorker.NOTIFICATION_ERROR_ID);
+                                    FileUploadWorker.NOTIFICATION_ERROR_ID);
 
     }
 

+ 7 - 7
app/src/main/java/com/owncloud/android/ui/dialog/parcel/SyncedFolderParcelable.java

@@ -23,7 +23,7 @@ package com.owncloud.android.ui.dialog.parcel;
 import android.os.Parcel;
 import android.os.Parcelable;
 
-import com.nextcloud.client.jobs.FilesUploadWorker;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.nextcloud.client.preferences.SubFolderRule;
 import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
@@ -134,11 +134,11 @@ public class SyncedFolderParcelable implements Parcelable {
 
     public Integer getUploadActionInteger() {
         switch (uploadAction) {
-            case FilesUploadWorker.LOCAL_BEHAVIOUR_FORGET:
+            case FileUploadWorker.LOCAL_BEHAVIOUR_FORGET:
                 return 0;
-            case FilesUploadWorker.LOCAL_BEHAVIOUR_MOVE:
+            case FileUploadWorker.LOCAL_BEHAVIOUR_MOVE:
                 return 1;
-            case FilesUploadWorker.LOCAL_BEHAVIOUR_DELETE:
+            case FileUploadWorker.LOCAL_BEHAVIOUR_DELETE:
                 return 2;
         }
         return 0;
@@ -147,13 +147,13 @@ public class SyncedFolderParcelable implements Parcelable {
     public void setUploadAction(String uploadAction) {
         switch (uploadAction) {
             case "LOCAL_BEHAVIOUR_FORGET":
-                this.uploadAction = FilesUploadWorker.LOCAL_BEHAVIOUR_FORGET;
+                this.uploadAction = FileUploadWorker.LOCAL_BEHAVIOUR_FORGET;
                 break;
             case "LOCAL_BEHAVIOUR_MOVE":
-                this.uploadAction = FilesUploadWorker.LOCAL_BEHAVIOUR_MOVE;
+                this.uploadAction = FileUploadWorker.LOCAL_BEHAVIOUR_MOVE;
                 break;
             case "LOCAL_BEHAVIOUR_DELETE":
-                this.uploadAction = FilesUploadWorker.LOCAL_BEHAVIOUR_DELETE;
+                this.uploadAction = FileUploadWorker.LOCAL_BEHAVIOUR_DELETE;
                 break;
             default:
                 // do nothing

+ 2 - 5
app/src/main/java/com/owncloud/android/utils/FilesSyncHelper.java

@@ -33,8 +33,8 @@ import android.provider.MediaStore;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.device.BatteryStatus;
 import com.nextcloud.client.device.PowerManagementService;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.nextcloud.client.jobs.BackgroundJobManager;
-import com.nextcloud.client.jobs.FilesUploadWorker;
 import com.nextcloud.client.network.ConnectivityService;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.datamodel.FilesystemDataProvider;
@@ -65,8 +65,6 @@ public final class FilesSyncHelper {
 
     public static final String GLOBAL = "global";
 
-    public static final int ContentSyncJobId = 315;
-
     private FilesSyncHelper() {
         // utility class -> private constructor
     }
@@ -229,8 +227,7 @@ public final class FilesSyncHelper {
 
         new Thread(() -> {
             if (connectivityService.getConnectivity().isConnected()) {
-                FilesUploadWorker.Companion.retryFailedUploads(
-                    context,
+                FileUploadWorker.Companion.retryFailedUploads(
                     uploadsStorageManager,
                     connectivityService,
                     accountManager,

+ 12 - 49
app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt

@@ -22,15 +22,13 @@
 
 package com.owncloud.android.utils
 
-import androidx.work.WorkInfo
-import androidx.work.WorkManager
-import com.google.common.util.concurrent.ListenableFuture
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.UserAccountManager
+import com.nextcloud.client.files.uploader.FileUploadWorker
+import com.nextcloud.client.files.uploader.FileUploadWorker.Companion.currentUploadFileOperation
 import com.nextcloud.client.jobs.BackgroundJobManager
 import com.nextcloud.client.jobs.BackgroundJobManagerImpl
-import com.nextcloud.client.jobs.FilesUploadWorker
-import com.nextcloud.client.jobs.FilesUploadWorker.Companion.currentUploadFileOperation
+import com.nextcloud.utils.extensions.isWorkScheduled
 import com.owncloud.android.MainApp
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.UploadsStorageManager
@@ -39,7 +37,6 @@ import com.owncloud.android.db.OCUpload
 import com.owncloud.android.files.services.NameCollisionPolicy
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener
 import com.owncloud.android.lib.common.utils.Log_OC
-import java.util.concurrent.ExecutionException
 import javax.inject.Inject
 
 @Suppress("TooManyFunctions")
@@ -58,7 +55,7 @@ class FilesUploadHelper {
     }
 
     companion object {
-        private val TAG = FilesUploadWorker::class.java.simpleName
+        private val TAG = FileUploadWorker::class.java.simpleName
 
         // TODO is needed with worker?
         // val pendingUploads = IndexedForest<UploadFileOperation>()
@@ -67,45 +64,6 @@ class FilesUploadHelper {
         fun buildRemoteName(accountName: String, remotePath: String): String {
             return accountName + remotePath
         }
-
-        fun onTransferProgress(
-            accountName: String?,
-            remotePath: String?,
-            progressRate: Long,
-            totalTransferredSoFar: Long,
-            totalToTransfer: Long,
-            fileName: String?
-        ) {
-            if (accountName == null || remotePath == null) return
-
-            val key: String =
-                buildRemoteName(accountName, remotePath)
-            val boundListener = mBoundListeners[key]
-
-            boundListener?.onTransferProgress(progressRate, totalTransferredSoFar, totalToTransfer, fileName)
-        }
-
-        fun isWorkScheduled(tag: String): Boolean {
-            val instance = WorkManager.getInstance(MainApp.getAppContext())
-            val statuses: ListenableFuture<List<WorkInfo>> = instance.getWorkInfosByTag(tag)
-            var running = false
-            var workInfoList: List<WorkInfo> = emptyList()
-
-            try {
-                workInfoList = statuses.get()
-            } catch (e: ExecutionException) {
-                Log_OC.d(TAG, "ExecutionException in isWorkScheduled: $e")
-            } catch (e: InterruptedException) {
-                Log_OC.d(TAG, "InterruptedException in isWorkScheduled: $e")
-            }
-
-            for (workInfo in workInfoList) {
-                val state = workInfo.state
-                running = running || (state == WorkInfo.State.RUNNING || state == WorkInfo.State.ENQUEUED)
-            }
-
-            return running
-        }
     }
 
     @Suppress("LongParameterList")
@@ -150,13 +108,17 @@ class FilesUploadHelper {
     }
 
     private fun restartUploadJob(user: User) {
-        backgroundJobManager.cancelFilesUploadJob(user)
-        backgroundJobManager.startFilesUploadJob(user)
+        backgroundJobManager.run {
+            cancelFilesUploadJob(user)
+            startFilesUploadJob(user)
+        }
     }
 
     @Suppress("ReturnCount")
     fun isUploading(user: User?, file: OCFile?): Boolean {
-        if (user == null || file == null || !isWorkScheduled(BackgroundJobManagerImpl.JOB_FILES_UPLOAD)) {
+        if (user == null || file == null || !MainApp.getAppContext()
+                .isWorkScheduled(BackgroundJobManagerImpl.JOB_FILES_UPLOAD)
+        ) {
             return false
         }
 
@@ -169,6 +131,7 @@ class FilesUploadHelper {
         val currentUploadFileOperation = currentUploadFileOperation
         if (currentUploadFileOperation == null || currentUploadFileOperation.user == null) return false
         if (upload == null || upload.accountName != currentUploadFileOperation.user.accountName) return false
+
         return if (currentUploadFileOperation.oldFile != null) {
             // For file conflicts check old file remote path
             upload.remotePath == currentUploadFileOperation.remotePath ||

+ 2 - 2
app/src/test/java/com/owncloud/android/ui/activity/SyncedFoldersActivityTest.java

@@ -22,7 +22,7 @@
 
 package com.owncloud.android.ui.activity;
 
-import com.nextcloud.client.jobs.FilesUploadWorker;
+import com.nextcloud.client.files.uploader.FileUploadWorker;
 import com.nextcloud.client.preferences.SubFolderRule;
 import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
@@ -169,7 +169,7 @@ public class SyncedFoldersActivityTest {
                                            true,
                                            true,
                                            "test@nextcloud.com",
-                                           FilesUploadWorker.LOCAL_BEHAVIOUR_MOVE,
+                                           FileUploadWorker.LOCAL_BEHAVIOUR_MOVE,
                                            NameCollisionPolicy.ASK_USER.serialize(),
                                            enabled,
                                            System.currentTimeMillis(),