Эх сурвалжийг харах

Rebase master

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 жил өмнө
parent
commit
0eca11f762

+ 0 - 38
app/src/androidTest/java/com/owncloud/android/files/services/FileUploadWorkerIT.kt

@@ -1,38 +0,0 @@
-/*
- *
- * Nextcloud Android client application
- *
- * @author Tobias Kaminsky
- * Copyright (C) 2022 Tobias Kaminsky
- * Copyright (C) 2022 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package com.owncloud.android.files.services
-
-import org.junit.After
-import org.junit.Before
-
-class FileUploadWorkerIT : FileUploaderIT() {
-    @Before
-    fun forceUploadWorker() {
-        FileUploader.setForceNewUploadWorker(true)
-    }
-
-    @After
-    fun resetForceUploadWorker() {
-        FileUploader.setForceNewUploadWorker(false)
-    }
-}

+ 1 - 2
app/src/main/java/com/nextcloud/client/files/uploader/FileUploaderIntents.kt

@@ -27,7 +27,6 @@ import android.content.Intent
 import android.os.Build
 import com.nextcloud.client.jobs.FilesUploadWorker
 import com.owncloud.android.authentication.AuthenticatorActivity
-import com.owncloud.android.files.services.FileUploader.UploadNotificationActionReceiver
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
 import com.owncloud.android.operations.UploadFileOperation
 import com.owncloud.android.ui.activity.ConflictsResolveActivity.Companion.createIntent
@@ -41,7 +40,7 @@ class FileUploaderIntents(private val context: Context) {
     fun startIntent(operation: UploadFileOperation): PendingIntent {
         val intent = Intent(
             context,
-            UploadNotificationActionReceiver::class.java
+            FilesUploadWorker.Companion.UploadNotificationActionReceiver::class.java
         ).apply {
             putExtra(FilesUploadWorker.EXTRA_ACCOUNT_NAME, operation.user.accountName)
             putExtra(FilesUploadWorker.EXTRA_REMOTE_PATH, operation.remotePath)

+ 170 - 0
app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt

@@ -22,7 +22,9 @@
 
 package com.nextcloud.client.jobs
 
+import android.content.BroadcastReceiver
 import android.content.Context
+import android.content.Intent
 import androidx.localbroadcastmanager.content.LocalBroadcastManager
 import androidx.work.Worker
 import androidx.work.WorkerParameters
@@ -33,11 +35,17 @@ import com.nextcloud.client.files.uploader.FileUploaderIntents
 import com.nextcloud.client.files.uploader.UploadNotificationManager
 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
+import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.ThumbnailsCacheManager
 import com.owncloud.android.datamodel.UploadsStorageManager
 import com.owncloud.android.db.OCUpload
+import com.owncloud.android.db.UploadResult
+import com.owncloud.android.files.services.FileUploader
+import com.owncloud.android.files.services.FileUploader.FileUploaderBinder
+import com.owncloud.android.files.services.NameCollisionPolicy
 import com.owncloud.android.lib.common.OwnCloudAccount
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener
@@ -316,5 +324,167 @@ class FilesUploadWorker(
         const val LOCAL_BEHAVIOUR_MOVE = 1
         const val LOCAL_BEHAVIOUR_FORGET = 2
         const val LOCAL_BEHAVIOUR_DELETE = 3
+
+        /**
+         * Upload and overwrite an already uploaded file with disabled retries
+         */
+        fun uploadUpdateFile(
+            context: Context?,
+            user: User,
+            existingFile: OCFile?,
+            behaviour: Int?,
+            nameCollisionPolicy: NameCollisionPolicy?
+        ) {
+            uploadUpdateFile(
+                context,
+                user, arrayOf(existingFile),
+                behaviour,
+                nameCollisionPolicy,
+                true
+            )
+        }
+
+        /**
+         * Upload and overwrite an already uploaded file
+         */
+        fun uploadUpdateFile(
+            context: Context?,
+            user: User,
+            existingFile: OCFile?,
+            behaviour: Int?,
+            nameCollisionPolicy: NameCollisionPolicy?,
+            disableRetries: Boolean
+        ) {
+            uploadUpdateFile(
+                context,
+                user, arrayOf(existingFile),
+                behaviour,
+                nameCollisionPolicy,
+                disableRetries
+            )
+        }
+
+        /**
+         * Upload and overwrite already uploaded files
+         */
+        fun uploadUpdateFile(
+            context: Context?,
+            user: User,
+            existingFiles: Array<OCFile?>?,
+            behaviour: Int?,
+            nameCollisionPolicy: NameCollisionPolicy?,
+            disableRetries: Boolean
+        ) {
+            val intent = Intent(context, FileUploader::class.java)
+            intent.putExtra(KEY_USER, user)
+            intent.putExtra(KEY_ACCOUNT, user.toPlatformAccount())
+            intent.putExtra(KEY_FILE, existingFiles)
+            intent.putExtra(KEY_LOCAL_BEHAVIOUR, behaviour)
+            intent.putExtra(KEY_NAME_COLLISION_POLICY, nameCollisionPolicy)
+            intent.putExtra(KEY_DISABLE_RETRIES, disableRetries)
+            FilesUploadHelper().uploadUpdatedFile(user, existingFiles!!, behaviour!!, nameCollisionPolicy!!)
+        }
+
+        /**
+         * Retry a failed [OCUpload] identified by [OCUpload.getRemotePath]
+         */
+        fun retryUpload(
+            context: Context,
+            user: User,
+            upload: OCUpload
+        ) {
+            val i = Intent(context, FileUploader::class.java)
+            i.putExtra(KEY_RETRY, true)
+            i.putExtra(KEY_USER, user)
+            i.putExtra(KEY_ACCOUNT, user.toPlatformAccount())
+            i.putExtra(KEY_RETRY_UPLOAD, upload)
+            FilesUploadHelper().retryUpload(upload, user)
+        }
+
+        /**
+         * Retry a subset of all the stored failed uploads.
+         */
+        fun retryFailedUploads(
+            context: Context,
+            uploadsStorageManager: UploadsStorageManager,
+            connectivityService: ConnectivityService,
+            accountManager: UserAccountManager,
+            powerManagementService: PowerManagementService
+        ) {
+            val failedUploads = uploadsStorageManager.failedUploads
+            if (failedUploads == null || failedUploads.size == 0) {
+                return  //nothing to do
+            }
+            val (gotNetwork, _, gotWifi) = connectivityService.connectivity
+            val batteryStatus = powerManagementService.battery
+            val charging = batteryStatus.isCharging || batteryStatus.isFull
+            val isPowerSaving = powerManagementService.isPowerSavingEnabled
+            var uploadUser = Optional.empty<User>()
+            for (failedUpload in failedUploads) {
+                // 1. extract failed upload owner account and cache it between loops (expensive query)
+                if (!uploadUser.isPresent || !uploadUser.get().nameEquals(failedUpload.accountName)) {
+                    uploadUser = accountManager.getUser(failedUpload.accountName)
+                }
+                val isDeleted = !File(failedUpload.localPath).exists()
+                if (isDeleted) {
+                    // 2A. for deleted files, mark as permanently failed
+                    if (failedUpload.lastResult != UploadResult.FILE_NOT_FOUND) {
+                        failedUpload.lastResult = UploadResult.FILE_NOT_FOUND
+                        uploadsStorageManager.updateUpload(failedUpload)
+                    }
+                } else if (!isPowerSaving && gotNetwork &&
+                    canUploadBeRetried(failedUpload, gotWifi, charging) && !connectivityService.isInternetWalled
+                ) {
+                    // 2B. for existing local files, try restarting it if possible
+                    retryUpload(context, uploadUser.get(), failedUpload)
+                }
+            }
+        }
+
+        private fun canUploadBeRetried(upload: OCUpload, gotWifi: Boolean, isCharging: Boolean): Boolean {
+            val file = File(upload.localPath)
+            val needsWifi = upload.isUseWifiOnly
+            val needsCharging = upload.isWhileChargingOnly
+            return file.exists() && (!needsWifi || gotWifi) && (!needsCharging || isCharging)
+        }
+
+        fun getUploadsAddedMessage(): String {
+            return FileUploader::class.java.name + UPLOADS_ADDED_MESSAGE
+        }
+
+        fun getUploadStartMessage(): String {
+            return FileUploader::class.java.name + UPLOAD_START_MESSAGE
+        }
+
+        fun getUploadFinishMessage(): String {
+            return FileUploader::class.java.name + UPLOAD_FINISH_MESSAGE
+        }
+
+        fun buildRemoteName(accountName: String, remotePath: String): String {
+            return accountName + remotePath
+        }
+
+        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,
+                        "Cancel broadcast received for file " + remotePath + " at " + System.currentTimeMillis()
+                    )
+                    if (accountName == null || remotePath == null) {
+                        return
+                    }
+                    val uploadBinder = FileUploader.mBinder as FileUploaderBinder
+                    uploadBinder.cancel(accountName, remotePath, null)
+                } else if (ACTION_PAUSE_BROADCAST == action) {
+
+                } else {
+                    Log_OC.d(TAG, "Unknown action to perform as UploadNotificationActionReceiver.")
+                }
+            }
+        }
     }
 }

+ 3 - 4
app/src/main/java/com/nextcloud/client/utils/FileUploaderDelegate.kt

@@ -26,7 +26,6 @@ import android.content.Context
 import android.content.Intent
 import androidx.localbroadcastmanager.content.LocalBroadcastManager
 import com.nextcloud.client.jobs.FilesUploadWorker
-import com.owncloud.android.files.services.FileUploader
 import com.owncloud.android.lib.common.operations.RemoteOperationResult
 import com.owncloud.android.operations.UploadFileOperation
 
@@ -37,7 +36,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(FileUploader.getUploadsAddedMessage())
+        val start = Intent(FilesUploadWorker.getUploadsAddedMessage())
         // nothing else needed right now
         start.setPackage(context.packageName)
         localBroadcastManager.sendBroadcast(start)
@@ -55,7 +54,7 @@ class FileUploaderDelegate {
         context: Context,
         localBroadcastManager: LocalBroadcastManager
     ) {
-        val start = Intent(FileUploader.getUploadStartMessage())
+        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)
@@ -79,7 +78,7 @@ class FileUploaderDelegate {
         context: Context,
         localBroadcastManager: LocalBroadcastManager
     ) {
-        val end = Intent(FileUploader.getUploadFinishMessage())
+        val end = Intent(FilesUploadWorker.getUploadFinishMessage())
         // real remote path, after possible automatic renaming
         end.putExtra(FilesUploadWorker.EXTRA_REMOTE_PATH, upload.remotePath)
         if (upload.wasRenamed()) {

+ 6 - 193
app/src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -111,15 +111,9 @@ public class FileUploader extends Service
 
     private static final String TAG = FileUploader.class.getSimpleName();
 
-
-
-
-
-    private static boolean forceNewUploadWorker = false;
-
     private Looper mServiceLooper;
     private ServiceHandler mServiceHandler;
-    private static IBinder mBinder;
+    public static IBinder mBinder;
     private OwnCloudClient mUploadClient;
     private Account mCurrentAccount;
     private FileDataStorageManager mStorageManager;
@@ -694,144 +688,7 @@ public class FileUploader extends Service
         mUploadsStorageManager.removeUploads(accountName);
     }
 
-    /**
-     * Upload and overwrite an already uploaded file with disabled retries
-     */
-    public static void uploadUpdateFile(
-        Context context,
-        User user,
-        OCFile existingFile,
-        Integer behaviour,
-        NameCollisionPolicy nameCollisionPolicy) {
-        uploadUpdateFile(context,
-                         user,
-                         new OCFile[]{existingFile},
-                         behaviour,
-                         nameCollisionPolicy,
-                         true);
-    }
 
-    /**
-     * Upload and overwrite an already uploaded file
-     */
-    public static void uploadUpdateFile(
-        Context context,
-        User user,
-        OCFile existingFile,
-        Integer behaviour,
-        NameCollisionPolicy nameCollisionPolicy,
-        boolean disableRetries) {
-        uploadUpdateFile(context,
-                         user,
-                         new OCFile[]{existingFile},
-                         behaviour,
-                         nameCollisionPolicy,
-                         disableRetries);
-    }
-
-    /**
-     * Upload and overwrite already uploaded files
-     */
-    public static void uploadUpdateFile(
-        Context context,
-        User user,
-        OCFile[] existingFiles,
-        Integer behaviour,
-        NameCollisionPolicy nameCollisionPolicy,
-        boolean disableRetries) {
-        Intent intent = new Intent(context, FileUploader.class);
-
-        intent.putExtra(FilesUploadWorker.KEY_USER, user);
-        intent.putExtra(FilesUploadWorker.KEY_ACCOUNT, user.toPlatformAccount());
-        intent.putExtra(FilesUploadWorker.KEY_FILE, existingFiles);
-        intent.putExtra(FilesUploadWorker.KEY_LOCAL_BEHAVIOUR, behaviour);
-        intent.putExtra(FilesUploadWorker.KEY_NAME_COLLISION_POLICY, nameCollisionPolicy);
-        intent.putExtra(FilesUploadWorker.KEY_DISABLE_RETRIES, disableRetries);
-
-        new FilesUploadHelper().uploadUpdatedFile(user, existingFiles, behaviour, nameCollisionPolicy);
-    }
-
-    /**
-     * Retry a failed {@link OCUpload} identified by {@link OCUpload#getRemotePath()}
-     */
-    public static void retryUpload(@NonNull Context context,
-                                   @NonNull User user,
-                                   @NonNull OCUpload upload) {
-        Intent i = new Intent(context, FileUploader.class);
-        i.putExtra(FilesUploadWorker.KEY_RETRY, true);
-        i.putExtra(FilesUploadWorker.KEY_USER, user);
-        i.putExtra(FilesUploadWorker.KEY_ACCOUNT, user.toPlatformAccount());
-        i.putExtra(FilesUploadWorker.KEY_RETRY_UPLOAD, upload);
-
-        new FilesUploadHelper().retryUpload(upload, user);
-    }
-
-    /**
-     * Retry a subset of all the stored failed uploads.
-     */
-    public static void retryFailedUploads(
-        @NonNull final Context context,
-        @NonNull final UploadsStorageManager uploadsStorageManager,
-        @NonNull final ConnectivityService connectivityService,
-        @NonNull final UserAccountManager accountManager,
-        @NonNull final PowerManagementService powerManagementService) {
-        OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
-        if (failedUploads == null || failedUploads.length == 0) {
-            return; //nothing to do
-        }
-
-        final Connectivity connectivity = connectivityService.getConnectivity();
-        final boolean gotNetwork = connectivity.isConnected();
-        final boolean gotWifi = connectivity.isWifi();
-        final BatteryStatus batteryStatus = powerManagementService.getBattery();
-        final boolean charging = batteryStatus.isCharging() || batteryStatus.isFull();
-        final boolean isPowerSaving = powerManagementService.isPowerSavingEnabled();
-
-        Optional<User> uploadUser = Optional.empty();
-        for (OCUpload failedUpload : failedUploads) {
-            // 1. extract failed upload owner account and cache it between loops (expensive query)
-            if (!uploadUser.isPresent() || !uploadUser.get().nameEquals(failedUpload.getAccountName())) {
-                uploadUser = accountManager.getUser(failedUpload.getAccountName());
-            }
-            final boolean isDeleted = !new File(failedUpload.getLocalPath()).exists();
-            if (isDeleted) {
-                // 2A. for deleted files, mark as permanently failed
-                if (failedUpload.getLastResult() != UploadResult.FILE_NOT_FOUND) {
-                    failedUpload.setLastResult(UploadResult.FILE_NOT_FOUND);
-                    uploadsStorageManager.updateUpload(failedUpload);
-                }
-            } else if (!isPowerSaving && gotNetwork &&
-                canUploadBeRetried(failedUpload, gotWifi, charging) && !connectivityService.isInternetWalled()) {
-                // 2B. for existing local files, try restarting it if possible
-                retryUpload(context, uploadUser.get(), failedUpload);
-            }
-        }
-    }
-
-    private static boolean canUploadBeRetried(OCUpload upload, boolean gotWifi, boolean isCharging) {
-        File file = new File(upload.getLocalPath());
-        boolean needsWifi = upload.isUseWifiOnly();
-        boolean needsCharging = upload.isWhileChargingOnly();
-
-        return file.exists() && (!needsWifi || gotWifi) && (!needsCharging || isCharging);
-    }
-
-    public static String getUploadsAddedMessage() {
-        return FileUploader.class.getName() + FilesUploadWorker.UPLOADS_ADDED_MESSAGE;
-    }
-
-    public static String getUploadStartMessage() {
-        return FileUploader.class.getName() + FilesUploadWorker.UPLOAD_START_MESSAGE;
-    }
-
-    public static String getUploadFinishMessage() {
-        return FileUploader.class.getName() + FilesUploadWorker.UPLOAD_FINISH_MESSAGE;
-    }
-
-    @VisibleForTesting
-    public static void setForceNewUploadWorker(final Boolean value) {
-        forceNewUploadWorker = value;
-    }
 
     /**
      * Binder to let client components to perform operations on the queue of uploads.
@@ -952,7 +809,7 @@ public class FileUploader extends Service
                 return;
             }
 
-            String targetKey = buildRemoteName(user.getAccountName(), file.getRemotePath());
+            String targetKey = FilesUploadWorker.Companion.buildRemoteName(user.getAccountName(), file.getRemotePath());
             new FilesUploadHelper().addDatatransferProgressListener(listener,targetKey);
         }
 
@@ -970,7 +827,7 @@ public class FileUploader extends Service
                 return;
             }
 
-            String targetKey = buildRemoteName(ocUpload.getAccountName(), ocUpload.getRemotePath());
+            String targetKey = FilesUploadWorker.Companion.buildRemoteName(ocUpload.getAccountName(), ocUpload.getRemotePath());
             new FilesUploadHelper().addDatatransferProgressListener(listener,targetKey);
         }
 
@@ -990,7 +847,7 @@ public class FileUploader extends Service
                 return;
             }
 
-            String targetKey = buildRemoteName(user.getAccountName(), file.getRemotePath());
+            String targetKey = FilesUploadWorker.Companion.buildRemoteName(user.getAccountName(), file.getRemotePath());
             new FilesUploadHelper().removeDatatransferProgressListener(listener,targetKey);
         }
 
@@ -1008,7 +865,7 @@ public class FileUploader extends Service
                 return;
             }
 
-            String targetKey = buildRemoteName(ocUpload.getAccountName(), ocUpload.getRemotePath());
+            String targetKey = FilesUploadWorker.Companion.buildRemoteName(ocUpload.getAccountName(), ocUpload.getRemotePath());
             new FilesUploadHelper().removeDatatransferProgressListener(listener,targetKey);
         }
 
@@ -1019,7 +876,7 @@ public class FileUploader extends Service
             long totalToTransfer,
             String fileName
                                       ) {
-            String key = buildRemoteName(mCurrentUpload.getUser().getAccountName(), mCurrentUpload.getFile().getRemotePath());
+            String key = FilesUploadWorker.Companion.buildRemoteName(mCurrentUpload.getUser().getAccountName(), mCurrentUpload.getFile().getRemotePath());
             OnDatatransferProgressListener boundListener = mBoundListeners.get(key);
 
             if (boundListener != null) {
@@ -1047,20 +904,6 @@ public class FileUploader extends Service
                 }
             }
         }
-
-        /**
-         * Builds a key for the map of listeners.
-         *
-         * TODO use method in IndexedForest, or refactor both to a common place add to local database) to better policy
-         * (add to local database, then upload)
-         *
-         * @param accountName Local name of the ownCloud account where the file to upload belongs.
-         * @param remotePath  Remote path to upload the file to.
-         * @return Key
-         */
-        public static String buildRemoteName(String accountName, String remotePath) {
-            return accountName + remotePath;
-        }
     }
 
     /**
@@ -1096,34 +939,4 @@ public class FileUploader extends Service
             mService.stopSelf(msg.arg1);
         }
     }
-
-
-    /**
-     * When cancel action in upload notification is pressed, cancel upload of item
-     */
-    public static class UploadNotificationActionReceiver extends BroadcastReceiver {
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-
-            String accountName = intent.getStringExtra(FilesUploadWorker.EXTRA_ACCOUNT_NAME);
-            String remotePath = intent.getStringExtra(FilesUploadWorker.EXTRA_REMOTE_PATH);
-            String action = intent.getAction();
-
-            if (FilesUploadWorker.ACTION_CANCEL_BROADCAST.equals(action)) {
-                Log_OC.d(TAG, "Cancel broadcast received for file " + remotePath + " at " + System.currentTimeMillis());
-
-                if (accountName == null || remotePath == null) {
-                    return;
-                }
-
-                FileUploaderBinder uploadBinder = (FileUploaderBinder) mBinder;
-                uploadBinder.cancel(accountName, remotePath, null);
-            } else if (FilesUploadWorker.ACTION_PAUSE_BROADCAST.equals(action)) {
-
-            } else {
-                Log_OC.d(TAG, "Unknown action to perform as UploadNotificationActionReceiver.");
-            }
-        }
-    }
 }

+ 1 - 1
app/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java

@@ -267,7 +267,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
 
                         // TODO disable upload notifications as DocumentsProvider users already show them
                         // upload file with FileUploader service (off main thread)
-                        FileUploader.uploadUpdateFile(
+                        FilesUploadWorker.Companion.uploadUpdateFile(
                             context,
                             user,
                             ocFile,

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

@@ -42,6 +42,7 @@ import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.core.Clock;
 import com.nextcloud.client.device.PowerManagementService;
 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;
@@ -198,7 +199,7 @@ public class UploadListActivity extends FileActivity {
 
         if(uploadsStorageManager.getFailedUploads().length > 0){
             // retry failed uploads
-            new Thread(() -> FileUploader.retryFailedUploads(
+            new Thread(() -> FilesUploadWorker.Companion.retryFailedUploads(
                 this,
                 uploadsStorageManager,
                 connectivityService,
@@ -229,9 +230,9 @@ public class UploadListActivity extends FileActivity {
         // Listen for upload messages
         uploadMessagesReceiver = new UploadMessagesReceiver();
         IntentFilter uploadIntentFilter = new IntentFilter();
-        uploadIntentFilter.addAction(FileUploader.getUploadsAddedMessage());
-        uploadIntentFilter.addAction(FileUploader.getUploadStartMessage());
-        uploadIntentFilter.addAction(FileUploader.getUploadFinishMessage());
+        uploadIntentFilter.addAction(FilesUploadWorker.Companion.getUploadsAddedMessage());
+        uploadIntentFilter.addAction(FilesUploadWorker.Companion.getUploadStartMessage());
+        uploadIntentFilter.addAction(FilesUploadWorker.Companion.getUploadFinishMessage());
         localBroadcastManager.registerReceiver(uploadMessagesReceiver, uploadIntentFilter);
 
         Log_OC.v(TAG, "onResume() end");

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

@@ -134,7 +134,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                     }
                 }
                 case FINISHED -> uploadsStorageManager.clearSuccessfulUploads();
-                case FAILED -> new Thread(() -> FileUploader.retryFailedUploads(
+                case FAILED -> new Thread(() -> FilesUploadWorker.Companion.retryFailedUploads(
                     parentActivity,
                     uploadsStorageManager,
                     connectivityService,
@@ -363,7 +363,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                 File file = new File(item.getLocalPath());
                 Optional<User> user = accountManager.getUser(item.getAccountName());
                 if (file.exists() && user.isPresent()) {
-                    FileUploader.retryUpload(parentActivity, user.get(), item);
+                    FilesUploadWorker.Companion.retryUpload(parentActivity, user.get(), item);
                     loadUploadItemsFromDb();
                 } else {
                     DisplayUtils.showSnackMessage(

+ 23 - 58
app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java

@@ -24,21 +24,19 @@ package com.owncloud.android.ui.preview;
 
 import android.annotation.SuppressLint;
 import android.content.BroadcastReceiver;
-import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.ServiceConnection;
 import android.os.Bundle;
-import android.os.IBinder;
 import android.view.MenuItem;
 import android.view.View;
 
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.editimage.EditImageActivity;
-import com.nextcloud.client.files.downloader.FileDownloadHelper;
-import com.nextcloud.client.files.downloader.FileDownloadWorker;
+import com.nextcloud.client.jobs.download.FileDownloadHelper;
+import com.nextcloud.client.jobs.download.FileDownloadWorker;
+import com.nextcloud.client.jobs.upload.FileUploadWorker;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.java.util.Optional;
 import com.nextcloud.model.WorkerState;
@@ -49,13 +47,10 @@ import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.VirtualFolderType;
-import com.owncloud.android.files.services.FileUploader;
-import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.operations.DownloadType;
 import com.owncloud.android.operations.RemoveFileOperation;
 import com.owncloud.android.operations.SynchronizeFileOperation;
 import com.owncloud.android.ui.activity.FileActivity;
@@ -82,10 +77,10 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
  */
 @SuppressWarnings("PMD.AvoidDuplicateLiterals")
 public class PreviewImageActivity extends FileActivity implements
-        FileFragment.ContainerActivity,
-        ViewPager.OnPageChangeListener,
-        OnRemoteOperationListener,
-        Injectable {
+    FileFragment.ContainerActivity,
+    ViewPager.OnPageChangeListener,
+    OnRemoteOperationListener,
+    Injectable {
 
     public static final String TAG = PreviewImageActivity.class.getSimpleName();
     public static final String EXTRA_VIRTUAL_TYPE = "EXTRA_VIRTUAL_TYPE";
@@ -307,7 +302,7 @@ public class PreviewImageActivity extends FileActivity implements
     }
 
     private void observeWorkerState() {
-       WorkerStateLiveData.Companion.instance().observe(this, state -> {
+        WorkerStateLiveData.Companion.instance().observe(this, state -> {
             if (state instanceof WorkerState.Download) {
                 Log_OC.d(TAG, "Download worker started");
                 isDownloadWorkStarted = true;
@@ -325,41 +320,11 @@ public class PreviewImageActivity extends FileActivity implements
         });
     }
 
-    @Override
-    protected ServiceConnection newTransferenceServiceConnection() {
-        return new PreviewImageServiceConnection();
-    }
-
-    /** Defines callbacks for service binding, passed to bindService() */
-    private class PreviewImageServiceConnection implements ServiceConnection {
-
-        @Override
-        public void onServiceConnected(ComponentName component, IBinder service) {
-            if (component.equals(new ComponentName(PreviewImageActivity.this,
-                    FileUploader.class))) {
-                Log_OC.d(TAG, "Upload service connected");
-                mUploaderBinder = (FileUploaderBinder) service;
-            }
-
-        }
-
-        @Override
-        public void onServiceDisconnected(ComponentName component) {
-            if (component.equals(new ComponentName(PreviewImageActivity.this,
-                    FileUploader.class))) {
-                Log_OC.d(TAG, "Upload service suddenly disconnected");
-                mUploaderBinder = null;
-            }
-        }
-    }
-
-
     @Override
     public void onStop() {
         super.onStop();
     }
 
-
     @Override
     public void onDestroy() {
         super.onDestroy();
@@ -374,7 +339,7 @@ public class PreviewImageActivity extends FileActivity implements
         localBroadcastManager.registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
 
         mUploadFinishReceiver = new UploadFinishReceiver();
-        IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.getUploadFinishMessage());
+        IntentFilter uploadIntentFilter = new IntentFilter(FileUploadWorker.Companion.getUploadFinishMessage());
         localBroadcastManager.registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
     }
 
@@ -445,7 +410,7 @@ public class PreviewImageActivity extends FileActivity implements
                 setDrawerIndicatorEnabled(false);
 
                 if (currentFile.isEncrypted() && !currentFile.isDown() &&
-                        !mPreviewImagePagerAdapter.pendingErrorAt(position)) {
+                    !mPreviewImagePagerAdapter.pendingErrorAt(position)) {
                     requestForDownload(currentFile);
                 }
 
@@ -540,7 +505,7 @@ public class PreviewImageActivity extends FileActivity implements
 
     public void toggleFullScreen() {
         boolean visible = (mFullScreenAnchorView.getSystemUiVisibility()
-                & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
+            & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
 
         if (visible) {
             hideSystemUI(mFullScreenAnchorView);
@@ -581,23 +546,23 @@ public class PreviewImageActivity extends FileActivity implements
 
 
     @SuppressLint("InlinedApi")
-	private void hideSystemUI(View anchorView) {
+    private void hideSystemUI(View anchorView) {
         anchorView.setSystemUiVisibility(
-                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION         // hides NAVIGATION BAR; Android >= 4.0
-            |   View.SYSTEM_UI_FLAG_FULLSCREEN              // hides STATUS BAR;     Android >= 4.1
-            |   View.SYSTEM_UI_FLAG_IMMERSIVE               // stays interactive;    Android >= 4.4
-            |   View.SYSTEM_UI_FLAG_LAYOUT_STABLE           // draw full window;     Android >= 4.1
-            |   View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN       // draw full window;     Android >= 4.1
-            |   View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  // draw full window;     Android >= 4.1
-        );
+            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION         // hides NAVIGATION BAR; Android >= 4.0
+                |   View.SYSTEM_UI_FLAG_FULLSCREEN              // hides STATUS BAR;     Android >= 4.1
+                |   View.SYSTEM_UI_FLAG_IMMERSIVE               // stays interactive;    Android >= 4.4
+                |   View.SYSTEM_UI_FLAG_LAYOUT_STABLE           // draw full window;     Android >= 4.1
+                |   View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN       // draw full window;     Android >= 4.1
+                |   View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  // draw full window;     Android >= 4.1
+                                        );
     }
 
     @SuppressLint("InlinedApi")
     private void showSystemUI(View anchorView) {
         anchorView.setSystemUiVisibility(
-                View.SYSTEM_UI_FLAG_LAYOUT_STABLE           // draw full window;     Android >= 4.1
-            |   View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN       // draw full window;     Android >= 4.1
-            |   View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  // draw full window;     Android >= 4.
-        );
+            View.SYSTEM_UI_FLAG_LAYOUT_STABLE           // draw full window;     Android >= 4.1
+                |   View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN       // draw full window;     Android >= 4.1
+                |   View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  // draw full window;     Android >= 4.
+                                        );
     }
 }

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

@@ -34,6 +34,7 @@ import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.device.BatteryStatus;
 import com.nextcloud.client.device.PowerManagementService;
 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;
@@ -229,13 +230,12 @@ public final class FilesSyncHelper {
 
         new Thread(() -> {
             if (connectivityService.getConnectivity().isConnected()) {
-                FileUploader.retryFailedUploads(
+                FilesUploadWorker.Companion.retryFailedUploads(
                     context,
                     uploadsStorageManager,
                     connectivityService,
                     accountManager,
-                    powerManagementService
-                                               );
+                    powerManagementService);
             }
         }).start();
     }

+ 17 - 10
app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt

@@ -24,6 +24,7 @@ package com.owncloud.android.utils
 
 import com.nextcloud.client.account.User
 import com.nextcloud.client.jobs.BackgroundJobManager
+import com.nextcloud.client.jobs.FilesUploadWorker
 import com.owncloud.android.MainApp
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.UploadsStorageManager
@@ -87,21 +88,27 @@ class FilesUploadHelper {
 
     fun uploadUpdatedFile(
         user: User,
-        existingFiles: Array<OCFile>,
+        existingFiles: Array<OCFile?>?,
         behaviour: Int,
         nameCollisionPolicy: NameCollisionPolicy
     ) {
+        if (existingFiles == null) {
+            return
+        }
+
         Log_OC.d(this, "upload updated file")
 
         val uploads = existingFiles.map { file ->
-            OCUpload(file, user).apply {
-                fileSize = file.fileLength
-                this.nameCollisionPolicy = nameCollisionPolicy
-                isCreateRemoteFolder = true
-                this.localAction = behaviour
-                isUseWifiOnly = false
-                isWhileChargingOnly = false
-                uploadStatus = UploadsStorageManager.UploadStatus.UPLOAD_IN_PROGRESS
+            file?.let {
+                OCUpload(file, user).apply {
+                    fileSize = file.fileLength
+                    this.nameCollisionPolicy = nameCollisionPolicy
+                    isCreateRemoteFolder = true
+                    this.localAction = behaviour
+                    isUseWifiOnly = false
+                    isWhileChargingOnly = false
+                    uploadStatus = UploadsStorageManager.UploadStatus.UPLOAD_IN_PROGRESS
+                }
             }
         }
         uploadsStorageManager.storeUploads(uploads)
@@ -147,7 +154,7 @@ class FilesUploadHelper {
             if (accountName == null || remotePath == null) return
 
             val key: String =
-                FileUploaderBinder.buildRemoteName(accountName, remotePath)
+                FilesUploadWorker.buildRemoteName(accountName, remotePath)
             val boundListener = mBoundListeners[key]
 
             boundListener?.onTransferProgress(progressRate, totalTransferredSoFar, totalToTransfer, fileName)