浏览代码

Merge master

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 年之前
父节点
当前提交
60ec295fee

+ 8 - 14
app/src/main/java/com/nextcloud/client/files/downloader/FileTransferService.kt

@@ -22,8 +22,6 @@ package com.nextcloud.client.files.downloader
 import android.app.Service
 import android.content.Context
 import android.content.Intent
-import android.content.pm.ServiceInfo
-import android.os.Build
 import android.os.IBinder
 import com.nextcloud.client.account.User
 import com.nextcloud.client.core.AsyncRunner
@@ -33,7 +31,9 @@ import com.nextcloud.client.logger.Logger
 import com.nextcloud.client.network.ClientFactory
 import com.nextcloud.client.network.ConnectivityService
 import com.nextcloud.client.notifications.AppNotificationManager
+import com.nextcloud.utils.ForegroundServiceHelper
 import com.owncloud.android.datamodel.FileDataStorageManager
+import com.owncloud.android.datamodel.ForegroundServiceType
 import com.owncloud.android.datamodel.UploadsStorageManager
 import dagger.android.AndroidInjection
 import javax.inject.Inject
@@ -109,18 +109,12 @@ class FileTransferService : Service() {
         }
 
         if (!isRunning) {
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
-                startForeground(
-                    AppNotificationManager.TRANSFER_NOTIFICATION_ID,
-                    notificationsManager.buildDownloadServiceForegroundNotification(),
-                    ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
-                )
-            } else {
-                startForeground(
-                    AppNotificationManager.TRANSFER_NOTIFICATION_ID,
-                    notificationsManager.buildDownloadServiceForegroundNotification()
-                )
-            }
+            ForegroundServiceHelper.startService(
+                this,
+                AppNotificationManager.TRANSFER_NOTIFICATION_ID,
+                notificationsManager.buildDownloadServiceForegroundNotification(),
+                ForegroundServiceType.DataSync
+            )
         }
 
         val request: Request = intent.getParcelableExtra(EXTRA_REQUEST)!!

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

@@ -56,6 +56,7 @@ import com.owncloud.android.ui.activity.ConflictsResolveActivity
 import com.owncloud.android.ui.activity.UploadListActivity
 import com.owncloud.android.ui.notifications.NotificationUtils
 import com.owncloud.android.utils.ErrorMessageAdapter
+import com.owncloud.android.utils.FilesUploadHelper
 import com.owncloud.android.utils.theme.ViewThemeUtils
 import java.io.File
 import java.security.SecureRandom
@@ -77,7 +78,6 @@ class FilesUploadWorker(
     private val notificationManager: NotificationManager =
         context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
     private val fileUploaderDelegate = FileUploaderDelegate()
-    private var currentUploadFileOperation: UploadFileOperation? = null
 
     override fun doWork(): Result {
         val accountName = inputData.getString(ACCOUNT)
@@ -378,6 +378,14 @@ class FilesUploadWorker(
             val text = String.format(context.getString(R.string.uploader_upload_in_progress_content), percent, fileName)
             notificationBuilder.setContentText(text)
             notificationManager.notify(FOREGROUND_SERVICE_ID, notificationBuilder.build())
+            FilesUploadHelper.onTransferProgress(
+                currentUploadFileOperation?.user?.accountName,
+                currentUploadFileOperation?.remotePath,
+                progressRate,
+                totalTransferredSoFar,
+                totalToTransfer,
+                fileAbsoluteName
+            )
         }
         lastPercent = percent
     }
@@ -393,5 +401,6 @@ class FilesUploadWorker(
         private const val FOREGROUND_SERVICE_ID: Int = 412
         private const val MAX_PROGRESS: Int = 100
         const val ACCOUNT = "data_account"
+        var currentUploadFileOperation: UploadFileOperation? = null
     }
 }

+ 8 - 10
app/src/main/java/com/nextcloud/client/media/PlayerService.kt

@@ -22,7 +22,6 @@ package com.nextcloud.client.media
 import android.app.PendingIntent
 import android.app.Service
 import android.content.Intent
-import android.content.pm.ServiceInfo
 import android.media.AudioManager
 import android.os.Build
 import android.os.Bundle
@@ -32,7 +31,9 @@ import android.widget.Toast
 import androidx.core.app.NotificationCompat
 import com.nextcloud.client.account.User
 import com.nextcloud.client.network.ClientFactory
+import com.nextcloud.utils.ForegroundServiceHelper
 import com.owncloud.android.R
+import com.owncloud.android.datamodel.ForegroundServiceType
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.ui.notifications.NotificationUtils
 import com.owncloud.android.utils.theme.ViewThemeUtils
@@ -173,15 +174,12 @@ class PlayerService : Service() {
             notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_MEDIA)
         }
 
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
-            startForeground(
-                R.string.media_notif_ticker,
-                notificationBuilder.build(),
-                ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
-            )
-        } else {
-            startForeground(R.string.media_notif_ticker, notificationBuilder.build())
-        }
+        ForegroundServiceHelper.startService(
+            this,
+            R.string.media_notif_ticker,
+            notificationBuilder.build(),
+            ForegroundServiceType.MediaPlayback
+        )
 
         isRunning = true
     }

+ 48 - 0
app/src/main/java/com/nextcloud/utils/ForegroundServiceHelper.kt

@@ -0,0 +1,48 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @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
+ * 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.nextcloud.utils
+
+import android.app.Notification
+import android.app.Service
+import android.os.Build
+import androidx.core.app.ServiceCompat
+import com.owncloud.android.datamodel.ForegroundServiceType
+
+object ForegroundServiceHelper {
+    fun startService(
+        service: Service,
+        id: Int,
+        notification: Notification,
+        foregroundServiceType: ForegroundServiceType
+    ) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+            ServiceCompat.startForeground(
+                service,
+                id,
+                notification,
+                foregroundServiceType.getId()
+            )
+        } else {
+            service.startForeground(id, notification)
+        }
+    }
+}

+ 45 - 0
app/src/main/java/com/owncloud/android/datamodel/ForegroundServiceType.kt

@@ -0,0 +1,45 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @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
+ * 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.datamodel
+
+import android.content.pm.ServiceInfo
+import android.os.Build
+import androidx.annotation.RequiresApi
+
+/**
+ * Enum to specify the type of foreground service.
+ * Use this enum when starting a foreground service to indicate its purpose.
+ * Note: Foreground service type is not available for older Android versions.
+ * This wrapper is designed for compatibility on those versions.
+ */
+enum class ForegroundServiceType {
+    DataSync, MediaPlayback;
+
+    @RequiresApi(Build.VERSION_CODES.Q)
+    fun getId(): Int {
+        return if (this == DataSync) {
+            ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
+        } else {
+            ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
+        }
+    }
+}

+ 18 - 0
app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java

@@ -345,6 +345,24 @@ public class UploadsStorageManager extends Observable {
         return getUploads(null, (String[]) null);
     }
 
+    public OCUpload getUploadByRemotePath(String remotePath){
+        OCUpload result = null;
+        Cursor cursor = getDB().query(
+            ProviderTableMeta.CONTENT_URI_UPLOADS,
+            null,
+            ProviderTableMeta.UPLOADS_REMOTE_PATH + "=?",
+            new String[]{remotePath},
+            ProviderTableMeta.UPLOADS_REMOTE_PATH+ " ASC");
+
+        if (cursor != null) {
+            if (cursor.moveToFirst()) {
+                result = createOCUploadFromCursor(cursor);
+            }
+        }
+        Log_OC.d(TAG, "Retrieve job " + result + " for remote path " + remotePath);
+        return result;
+    }
+
     public @Nullable
     OCUpload getUploadById(long id) {
         OCUpload result = null;

+ 7 - 16
app/src/main/java/com/owncloud/android/files/services/FileDownloader.java

@@ -28,10 +28,8 @@ import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.app.Service;
 import android.content.Intent;
-import android.content.pm.ServiceInfo;
 import android.graphics.BitmapFactory;
 import android.os.Binder;
-import android.os.Build;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.IBinder;
@@ -44,9 +42,11 @@ import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.files.downloader.DownloadTask;
 import com.nextcloud.java.util.Optional;
+import com.nextcloud.utils.ForegroundServiceHelper;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.ForegroundServiceType;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.lib.common.OwnCloudAccount;
@@ -83,7 +83,6 @@ import java.util.Vector;
 import javax.inject.Inject;
 
 import androidx.core.app.NotificationCompat;
-import androidx.core.app.ServiceCompat;
 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
 import dagger.android.AndroidInjection;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -156,7 +155,7 @@ public class FileDownloader extends Service
         mBinder = new FileDownloaderBinder();
 
         NotificationCompat.Builder builder = NotificationUtils.newNotificationBuilder(this, viewThemeUtils).setContentTitle(
-            getApplicationContext().getResources().getString(R.string.app_name))
+                getApplicationContext().getResources().getString(R.string.app_name))
             .setContentText(getApplicationContext().getResources().getString(R.string.foreground_service_download))
             .setSmallIcon(R.drawable.notification_icon)
             .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_icon));
@@ -195,23 +194,15 @@ public class FileDownloader extends Service
 
     /**
      * Entry point to add one or several files to the queue of downloads.
-     *
-     * New downloads are added calling to startService(), resulting in a call to this method.
-     * This ensures the service will keep on working although the caller activity goes away.
+     * <p>
+     * New downloads are added calling to startService(), resulting in a call to this method. This ensures the service
+     * will keep on working although the caller activity goes away.
      */
     @Override
     public int onStartCommand(Intent intent, int flags, int startId) {
         Log_OC.d(TAG, "Starting command with id " + startId);
 
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
-            ServiceCompat.startForeground(
-                this,
-                FOREGROUND_SERVICE_ID,
-                mNotification,
-                ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
-        } else {
-            startForeground(FOREGROUND_SERVICE_ID, mNotification);
-        }
+        ForegroundServiceHelper.INSTANCE.startService(this, FOREGROUND_SERVICE_ID, mNotification, ForegroundServiceType.DataSync);
 
         if (intent == null || !intent.hasExtra(EXTRA_USER) || !intent.hasExtra(EXTRA_FILE)) {
             Log_OC.e(TAG, "Not enough information provided in intent");

+ 91 - 46
app/src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -37,7 +37,6 @@ import android.app.Service;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
-import android.content.pm.ServiceInfo;
 import android.graphics.BitmapFactory;
 import android.os.Binder;
 import android.os.Build;
@@ -59,10 +58,12 @@ import com.nextcloud.client.network.Connectivity;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.client.utils.FileUploaderDelegate;
 import com.nextcloud.java.util.Optional;
+import com.nextcloud.utils.ForegroundServiceHelper;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.ForegroundServiceType;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.UploadsStorageManager;
@@ -315,11 +316,7 @@ public class FileUploader extends Service
     public int onStartCommand(Intent intent, int flags, int startId) {
         Log_OC.d(TAG, "Starting command with id " + startId);
 
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
-            startForeground(FOREGROUND_SERVICE_ID, mNotification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
-        } else {
-            startForeground(FOREGROUND_SERVICE_ID, mNotification);
-        }
+        ForegroundServiceHelper.INSTANCE.startService(this, FOREGROUND_SERVICE_ID, mNotification, ForegroundServiceType.DataSync);
 
         if (intent == null) {
             Log_OC.e(TAG, "Intent is null");
@@ -389,7 +386,7 @@ public class FileUploader extends Service
         List<String> requestedUploads,
         boolean onWifiOnly,
         boolean whileChargingOnly
-    ) {
+                                            ) {
         String[] localPaths = null;
         String[] remotePaths = null;
         String[] mimeTypes = null;
@@ -428,7 +425,7 @@ public class FileUploader extends Service
                     remotePaths[i],
                     localPaths[i],
                     mimeTypes != null ? mimeTypes[i] : null
-                );
+                                                                      );
                 if (files[i] == null) {
                     Log_OC.e(TAG, "obtainNewOCFileToUpload() returned null for remotePaths[i]:" + remotePaths[i]
                         + " and localPaths[i]:" + localPaths[i]);
@@ -528,7 +525,7 @@ public class FileUploader extends Service
             user.getAccountName(),
             file.getRemotePath(),
             newUpload
-        );
+                                                                    );
 
         if (putResult != null) {
             requestedUploads.add(putResult.first);
@@ -575,7 +572,7 @@ public class FileUploader extends Service
             user.getAccountName(),
             upload.getRemotePath(),
             newUpload
-        );
+                                                                    );
         if (putResult != null) {
             String uploadKey = putResult.first;
             requestedUploads.add(uploadKey);
@@ -717,12 +714,12 @@ public class FileUploader extends Service
      */
     private void notifyUploadStart(UploadFileOperation upload) {
         // / create status notification with a progress bar
-        Intent notificationActionIntent = new Intent(getApplicationContext(),UploadNotificationActionReceiver.class);
-        notificationActionIntent.putExtra(EXTRA_ACCOUNT_NAME,upload.getUser().getAccountName());
-        notificationActionIntent.putExtra(EXTRA_REMOTE_PATH,upload.getRemotePath());
+        Intent notificationActionIntent = new Intent(getApplicationContext(), UploadNotificationActionReceiver.class);
+        notificationActionIntent.putExtra(EXTRA_ACCOUNT_NAME, upload.getUser().getAccountName());
+        notificationActionIntent.putExtra(EXTRA_REMOTE_PATH, upload.getRemotePath());
         notificationActionIntent.setAction(ACTION_CANCEL_BROADCAST);
 
-        PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),secureRandomGenerator.nextInt(),notificationActionIntent, PendingIntent.FLAG_IMMUTABLE);
+        PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), secureRandomGenerator.nextInt(), notificationActionIntent, PendingIntent.FLAG_IMMUTABLE);
         mLastPercent = 0;
         mNotificationBuilder = NotificationUtils.newNotificationBuilder(this, viewThemeUtils);
         mNotificationBuilder
@@ -735,7 +732,7 @@ public class FileUploader extends Service
                 String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName())
                            )
             .clearActions() // to make sure there is only one action
-            .addAction(R.drawable.ic_action_cancel_grey,getApplicationContext().getString(R.string.common_cancel),pendingIntent);
+            .addAction(R.drawable.ic_action_cancel_grey, getApplicationContext().getString(R.string.common_cancel), pendingIntent);
 
 
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -773,7 +770,7 @@ public class FileUploader extends Service
         long totalTransferredSoFar,
         long totalToTransfer,
         String filePath
-    ) {
+                                  ) {
         int percent = (int) (100.0 * ((double) totalTransferredSoFar) / ((double) totalToTransfer));
         if (percent != mLastPercent) {
             mNotificationBuilder.setProgress(100, percent, false);
@@ -839,11 +836,11 @@ public class FileUploader extends Service
                 Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
                 updateAccountCredentials.putExtra(
                     AuthenticatorActivity.EXTRA_ACCOUNT, upload.getUser().toPlatformAccount()
-                );
+                                                 );
                 updateAccountCredentials.putExtra(
                     AuthenticatorActivity.EXTRA_ACTION,
                     AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN
-                );
+                                                 );
 
                 updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
@@ -853,7 +850,7 @@ public class FileUploader extends Service
                     (int) System.currentTimeMillis(),
                     updateAccountCredentials,
                     PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE
-                ));
+                                                                               ));
             } else {
                 Intent intent;
                 if (uploadResult.getCode() == ResultCode.SYNC_CONFLICT) {
@@ -1179,11 +1176,11 @@ public class FileUploader extends Service
          */
         public void cancel(String accountName, String remotePath, @Nullable ResultCode resultCode) {
             // Cancel for Android version >= Android 11
-            if (useFilesUploadWorker(getApplicationContext())){
-                try{
+            if (useFilesUploadWorker(getApplicationContext())) {
+                try {
                     new FilesUploadHelper().cancelFileUpload(remotePath, accountManager.getUser(accountName).get());
-                }catch(NoSuchElementException e){
-                    Log_OC.e(TAG,"Error cancelling current upload because user does not exist!");
+                } catch (NoSuchElementException e) {
+                    Log_OC.e(TAG, "Error cancelling current upload because user does not exist!");
                 }
             } else {
                 // Cancel for Android version <= Android 10
@@ -1222,7 +1219,7 @@ public class FileUploader extends Service
             cancelPendingUploads(accountName);
             if (useFilesUploadWorker(getApplicationContext())) {
                 new FilesUploadHelper().restartUploadJob(accountManager.getUser(accountName).get());
-            }else{
+            } else {
                 if (mCurrentUpload != null && mCurrentUpload.getUser().nameEquals(accountName)) {
                     mCurrentUpload.cancel(ResultCode.CANCELLED);
                 }
@@ -1231,6 +1228,7 @@ public class FileUploader extends Service
         }
 
         public void clearListeners() {
+            FilesUploadHelper.Progress.getMBoundListeners().clear();
             mBoundListeners.clear();
         }
 
@@ -1250,16 +1248,43 @@ public class FileUploader extends Service
             if (user == null || file == null) {
                 return false;
             }
+            if (useFilesUploadWorker(getApplicationContext())){
+                // Not same as for service because upload list is "created" on the spot in the worker and not available here
+
+                 OCUpload upload = mUploadsStorageManager.getUploadByRemotePath(file.getRemotePath());
+                 if (upload == null){
+                     return false;
+                 }
+                 return upload.getUploadStatus() == UploadStatus.UPLOAD_IN_PROGRESS;
 
-            return mPendingUploads.contains(user.getAccountName(), file.getRemotePath());
+            }else{
+                return mPendingUploads.contains(user.getAccountName(), file.getRemotePath());
+            }
         }
 
+        @SuppressFBWarnings("NP")
         public boolean isUploadingNow(OCUpload upload) {
-            return upload != null &&
-                mCurrentAccount != null &&
-                mCurrentUpload != null &&
-                upload.getAccountName().equals(mCurrentAccount.name) &&
-                upload.getRemotePath().equals(mCurrentUpload.getRemotePath());
+            if (useFilesUploadWorker(getApplicationContext())){
+                UploadFileOperation currentUploadFileOperation = FilesUploadWorker.Companion.getCurrentUploadFileOperation();
+                if (currentUploadFileOperation == null || currentUploadFileOperation.getUser() == null) return false;
+                if (upload == null || (!upload.getAccountName().equals(currentUploadFileOperation.getUser().getAccountName()))) return false;
+                if (currentUploadFileOperation.getOldFile() != null){
+                    // For file conflicts check old file remote path
+                    return upload.getRemotePath().equals(currentUploadFileOperation.getRemotePath()) ||
+                        upload.getRemotePath().equals(currentUploadFileOperation.getOldFile().getRemotePath());
+                }
+                return upload.getRemotePath().equals(currentUploadFileOperation.getRemotePath());
+
+            }else {
+
+                return upload != null &&
+                    mCurrentAccount != null &&
+                    mCurrentUpload != null &&
+                    upload.getAccountName().equals(mCurrentAccount.name) &&
+                    (upload.getRemotePath().equals(mCurrentUpload.getRemotePath()) ||
+                        (mCurrentUpload.getOldFile() != null &&
+                            upload.getRemotePath().equals(mCurrentUpload.getOldFile().getRemotePath())));
+            }
         }
 
         /**
@@ -1273,13 +1298,17 @@ public class FileUploader extends Service
             OnDatatransferProgressListener listener,
             User user,
             OCFile file
-        ) {
+                                                   ) {
             if (user == null || file == null || listener == null) {
                 return;
             }
-
             String targetKey = buildRemoteName(user.getAccountName(), file.getRemotePath());
-            mBoundListeners.put(targetKey, listener);
+
+            if (useFilesUploadWorker(getApplicationContext())) {
+                new FilesUploadHelper().addDatatransferProgressListener(listener,targetKey);
+            }else {
+                mBoundListeners.put(targetKey, listener);
+            }
         }
 
         /**
@@ -1291,13 +1320,17 @@ public class FileUploader extends Service
         public void addDatatransferProgressListener(
             OnDatatransferProgressListener listener,
             OCUpload ocUpload
-        ) {
+                                                   ) {
             if (ocUpload == null || listener == null) {
                 return;
             }
 
             String targetKey = buildRemoteName(ocUpload.getAccountName(), ocUpload.getRemotePath());
-            mBoundListeners.put(targetKey, listener);
+            if (useFilesUploadWorker(getApplicationContext())) {
+                new FilesUploadHelper().addDatatransferProgressListener(listener,targetKey);
+            }else {
+                mBoundListeners.put(targetKey, listener);
+            }
         }
 
         /**
@@ -1311,14 +1344,19 @@ public class FileUploader extends Service
             OnDatatransferProgressListener listener,
             User user,
             OCFile file
-        ) {
+                                                      ) {
             if (user == null || file == null || listener == null) {
                 return;
             }
 
             String targetKey = buildRemoteName(user.getAccountName(), file.getRemotePath());
-            if (mBoundListeners.get(targetKey) == listener) {
-                mBoundListeners.remove(targetKey);
+
+            if (useFilesUploadWorker(getApplicationContext())) {
+                new FilesUploadHelper().removeDatatransferProgressListener(listener,targetKey);
+            }else {
+                if (mBoundListeners.get(targetKey) == listener) {
+                    mBoundListeners.remove(targetKey);
+                }
             }
         }
 
@@ -1331,14 +1369,19 @@ public class FileUploader extends Service
         public void removeDatatransferProgressListener(
             OnDatatransferProgressListener listener,
             OCUpload ocUpload
-        ) {
+                                                      ) {
             if (ocUpload == null || listener == null) {
                 return;
             }
 
             String targetKey = buildRemoteName(ocUpload.getAccountName(), ocUpload.getRemotePath());
-            if (mBoundListeners.get(targetKey) == listener) {
-                mBoundListeners.remove(targetKey);
+
+            if (useFilesUploadWorker(getApplicationContext())) {
+                new FilesUploadHelper().removeDatatransferProgressListener(listener,targetKey);
+            }else {
+                if (mBoundListeners.get(targetKey) == listener) {
+                    mBoundListeners.remove(targetKey);
+                }
             }
         }
 
@@ -1348,7 +1391,7 @@ public class FileUploader extends Service
             long totalTransferredSoFar,
             long totalToTransfer,
             String fileName
-        ) {
+                                      ) {
             String key = buildRemoteName(mCurrentUpload.getUser().getAccountName(), mCurrentUpload.getFile().getRemotePath());
             OnDatatransferProgressListener boundListener = mBoundListeners.get(key);
 
@@ -1373,7 +1416,7 @@ public class FileUploader extends Service
                         mCurrentUpload.getUser().getAccountName(),
                         mCurrentUpload.getFile().getRemotePath(),
                         cancelReason
-                    );
+                          );
                 }
             }
         }
@@ -1388,7 +1431,7 @@ public class FileUploader extends Service
          * @param remotePath  Remote path to upload the file to.
          * @return Key
          */
-        private String buildRemoteName(String accountName, String remotePath) {
+        public static String buildRemoteName(String accountName, String remotePath) {
             return accountName + remotePath;
         }
     }
@@ -1444,11 +1487,13 @@ public class FileUploader extends Service
             if (ACTION_CANCEL_BROADCAST.equals(action)) {
                 Log_OC.d(TAG, "Cancel broadcast received for file " + remotePath + " at " + System.currentTimeMillis());
 
-                if (accountName == null || remotePath == null) return;
+                if (accountName == null || remotePath == null) {
+                    return;
+                }
 
                 FileUploaderBinder uploadBinder = (FileUploaderBinder) mBinder;
                 uploadBinder.cancel(accountName, remotePath, null);
-            }else if(ACTION_PAUSE_BROADCAST.equals(action)){
+            } else if (ACTION_PAUSE_BROADCAST.equals(action)) {
 
             } else {
                 Log_OC.d(TAG, "Unknown action to perform as UploadNotificationActionReceiver.");

+ 0 - 1
app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -882,7 +882,6 @@ public class FileDisplayActivity extends FileActivity
      */
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-
         if (requestCode == REQUEST_CODE__SELECT_CONTENT_FROM_APPS &&
             (resultCode == RESULT_OK ||
                 resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {

+ 1 - 0
app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java

@@ -328,6 +328,7 @@ public class UploadListActivity extends FileActivity {
                     mUploaderBinder = (FileUploaderBinder) service;
                     Log_OC.d(TAG, "UploadListActivity connected to Upload service. component: " +
                             component + " service: " + service);
+                    uploadListAdapter.loadUploadItemsFromDb();
                 } else {
                     Log_OC.d(TAG, "mUploaderBinder already set. mUploaderBinder: " +
                             mUploaderBinder + " service:" + service);

+ 40 - 0
app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt

@@ -28,7 +28,9 @@ import com.owncloud.android.MainApp
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.UploadsStorageManager
 import com.owncloud.android.db.OCUpload
+import com.owncloud.android.files.services.FileUploader.FileUploaderBinder
 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 javax.inject.Inject
 
@@ -114,4 +116,42 @@ class FilesUploadHelper {
 
         backgroundJobManager.startFilesUploadJob(user)
     }
+
+    fun addDatatransferProgressListener(
+        listener: OnDatatransferProgressListener,
+        targetKey: String
+    ) {
+        mBoundListeners[targetKey] = listener
+    }
+
+    fun removeDatatransferProgressListener(
+        listener: OnDatatransferProgressListener,
+        targetKey: String
+    ) {
+        if (mBoundListeners[targetKey] === listener) {
+            mBoundListeners.remove(targetKey)
+        }
+    }
+
+    companion object Progress {
+        val mBoundListeners = HashMap<String, OnDatatransferProgressListener>()
+
+        fun onTransferProgress(
+            accountName: String?,
+            remotePath: String?,
+            progressRate: Long,
+            totalTransferredSoFar: Long,
+            totalToTransfer: Long,
+            fileName: String?
+        ) {
+            if (accountName == null || remotePath == null) return
+
+            val key: String =
+                FileUploaderBinder.buildRemoteName(accountName, remotePath)
+            val boundListener = mBoundListeners[key]
+
+            boundListener?.onTransferProgress(progressRate, totalTransferredSoFar, totalToTransfer, fileName)
+            Log_OC.d("TAG", "Hello")
+        }
+    }
 }

+ 1 - 1
scripts/analysis/lint-results.txt

@@ -1,2 +1,2 @@
 DO NOT TOUCH; GENERATED BY DRONE
-      <span class="mdl-layout-title">Lint Report: 9 errors and 75 warnings</span>
+      <span class="mdl-layout-title">Lint Report: 3 errors and 75 warnings</span>