瀏覽代碼

Solve git conflicts

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 年之前
父節點
當前提交
1b8e25b77b

+ 0 - 4
app/src/main/AndroidManifest.xml

@@ -393,10 +393,6 @@
         <service
             android:name=".services.OperationsService"
             android:exported="false" />
-        <service
-            android:name=".files.services.FileDownloader"
-            android:foregroundServiceType="dataSync"
-            android:exported="false" />
         <service
             android:name="com.nextcloud.client.files.downloader.FileTransferService"
             android:foregroundServiceType="dataSync"

+ 2 - 0
app/src/main/java/com/nextcloud/client/di/ComponentsModule.java

@@ -136,6 +136,8 @@ import com.owncloud.android.ui.preview.pdf.PreviewPdfFragment;
 import com.owncloud.android.ui.trashbin.TrashbinActivity;
 import com.owncloud.android.utils.FilesUploadHelper;
 
+import java.io.File;
+
 import dagger.Module;
 import dagger.android.ContributesAndroidInjector;
 

+ 26 - 7
app/src/main/java/com/nextcloud/client/files/downloader/DownloadWorker.kt → app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt

@@ -22,18 +22,37 @@
 package com.nextcloud.client.files.downloader
 
 import android.content.Context
-import android.content.Intent
+import androidx.localbroadcastmanager.content.LocalBroadcastManager
 import androidx.work.Worker
 import androidx.work.WorkerParameters
-import com.owncloud.android.files.services.FileDownloader
+import com.nextcloud.client.account.UserAccountManager
+import com.owncloud.android.datamodel.UploadsStorageManager
+import com.owncloud.android.utils.theme.ViewThemeUtils
 
-class DownloadWorker(
-    private val context: Context,
+class FilesDownloadWorker(
+    private val viewThemeUtils: ViewThemeUtils,
+    private val accountManager: UserAccountManager,
+    private val uploadsStorageManager: UploadsStorageManager,
+    private var localBroadcastManager: LocalBroadcastManager,
+    context: Context,
     params: WorkerParameters,
-    private val intent: Intent,
-    private val fileDownloader: FileDownloader,
 ) : Worker(context, params) {
+
+    companion object {
+        const val USER = "USER"
+        const val FILE = "FILE"
+        const val BEHAVIOUR = "BEHAVIOUR"
+        const val DOWNLOAD_TYPE = "DOWNLOAD_TYPE"
+        const val ACTIVITY_NAME = "ACTIVITY_NAME"
+        const val PACKAGE_NAME = "PACKAGE_NAME"
+        const val CONFLICT_UPLOAD_ID = "CONFLICT_UPLOAD_ID"
+    }
+
     override fun doWork(): Result {
-        TODO("Not yet implemented")
+        return try {
+            Result.success()
+        } catch (t: Throwable) {
+            Result.failure()
+        }
     }
 }

+ 13 - 0
app/src/main/java/com/nextcloud/client/jobs/BackgroundJobFactory.kt

@@ -34,6 +34,7 @@ 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.FilesDownloadWorker
 import com.nextcloud.client.integrations.deck.DeckApi
 import com.nextcloud.client.logger.Logger
 import com.nextcloud.client.network.ConnectivityService
@@ -102,6 +103,7 @@ class BackgroundJobFactory @Inject constructor(
                 CalendarImportWork::class -> createCalendarImportWork(context, workerParameters)
                 FilesExportWork::class -> createFilesExportWork(context, workerParameters)
                 FilesUploadWorker::class -> createFilesUploadWorker(context, workerParameters)
+                FilesDownloadWorker::class -> createFilesDownloadWorker(context, workerParameters)
                 GeneratePdfFromImagesWork::class -> createPDFGenerateWork(context, workerParameters)
                 HealthStatusWork::class -> createHealthStatusWork(context, workerParameters)
                 TestJob::class -> createTestJob(context, workerParameters)
@@ -253,6 +255,17 @@ class BackgroundJobFactory @Inject constructor(
         )
     }
 
+    private fun createFilesDownloadWorker(context: Context, params: WorkerParameters): FilesDownloadWorker {
+        return FilesDownloadWorker(
+            viewThemeUtils.get(),
+            accountManager,
+            uploadsStorageManager,
+            localBroadcastManager.get(),
+            context,
+            params
+        )
+    }
+
     private fun createPDFGenerateWork(context: Context, params: WorkerParameters): GeneratePdfFromImagesWork {
         return GeneratePdfFromImagesWork(
             appContext = context,

+ 11 - 0
app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt

@@ -23,6 +23,7 @@ import androidx.lifecycle.LiveData
 import androidx.work.ListenableWorker
 import com.nextcloud.client.account.User
 import com.owncloud.android.datamodel.OCFile
+import com.owncloud.android.operations.DownloadType
 
 /**
  * This interface allows to control, schedule and monitor all application
@@ -144,6 +145,16 @@ interface BackgroundJobManager {
     fun getFileUploads(user: User): LiveData<List<JobInfo>>
     fun cancelFilesUploadJob(user: User)
 
+    fun startFilesDownloadJob(
+        user: User,
+        ocFile: OCFile,
+        behaviour: String,
+        downloadType: DownloadType,
+        activityName: String,
+        packageName: String,
+        conflictUploadId: Long
+    )
+
     fun startPdfGenerateAndUploadWork(user: User, uploadFolder: String, imagePaths: List<String>, pdfPath: String)
 
     fun scheduleTestJob()

+ 30 - 0
app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt

@@ -38,8 +38,11 @@ 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.FilesDownloadWorker
 import com.nextcloud.client.preferences.AppPreferences
 import com.owncloud.android.datamodel.OCFile
+import com.owncloud.android.operations.DownloadType
+import java.io.File
 import java.util.Date
 import java.util.UUID
 import java.util.concurrent.TimeUnit
@@ -83,6 +86,7 @@ internal class BackgroundJobManagerImpl(
         const val JOB_NOTIFICATION = "notification"
         const val JOB_ACCOUNT_REMOVAL = "account_removal"
         const val JOB_FILES_UPLOAD = "files_upload"
+        const val JOB_FILES_DOWNLOAD = "files_download"
         const val JOB_PDF_GENERATION = "pdf_generation"
         const val JOB_IMMEDIATE_CALENDAR_BACKUP = "immediate_calendar_backup"
         const val JOB_IMMEDIATE_FILES_EXPORT = "immediate_files_export"
@@ -505,6 +509,32 @@ internal class BackgroundJobManagerImpl(
         workManager.enqueueUniqueWork(JOB_FILES_UPLOAD + user.accountName, ExistingWorkPolicy.KEEP, request)
     }
 
+    override fun startFilesDownloadJob(
+        user: User,
+        ocFile: OCFile,
+        behaviour: String,
+        downloadType: DownloadType,
+        activityName: String,
+        packageName: String,
+        conflictUploadId: Long
+    ) {
+        val data = workDataOf(
+            FilesDownloadWorker.USER to user,
+            FilesDownloadWorker.FILE to ocFile,
+            FilesDownloadWorker.BEHAVIOUR to behaviour,
+            FilesDownloadWorker.DOWNLOAD_TYPE to downloadType,
+            FilesDownloadWorker.ACTIVITY_NAME to activityName,
+            FilesDownloadWorker.PACKAGE_NAME to packageName,
+            FilesDownloadWorker.CONFLICT_UPLOAD_ID to conflictUploadId,
+        )
+
+        val request = oneTimeRequestBuilder(FilesDownloadWorker::class, JOB_FILES_DOWNLOAD, user)
+            .setInputData(data)
+            .build()
+
+        workManager.enqueueUniqueWork(JOB_FILES_DOWNLOAD + user.accountName, ExistingWorkPolicy.REPLACE, request)
+    }
+
     override fun getFileUploads(user: User): LiveData<List<JobInfo>> {
         val workInfo = workManager.getWorkInfosByTagLiveData(formatNameTag(JOB_FILES_UPLOAD, user))
         return workInfo.map { it -> it.map { fromWorkInfo(it) ?: JobInfo() } }

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

@@ -118,7 +118,8 @@ class FilesExportWork(
         i.putExtra(SendShareDialog.PACKAGE_NAME, "")
         i.putExtra(SendShareDialog.ACTIVITY_NAME, "")
         i.putExtra(FileDownloader.DOWNLOAD_TYPE, DownloadType.EXPORT)
-        appContext.startService(i)
+
+        FileDownloader(i)
     }
 
     private fun showErrorNotification(successfulExports: Int) {

+ 38 - 49
app/src/main/java/com/owncloud/android/files/services/FileDownloader.java

@@ -23,11 +23,10 @@ package com.owncloud.android.files.services;
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.accounts.OnAccountsUpdateListener;
-import android.app.Activity;
 import android.app.Notification;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
-import android.app.Service;
+import android.content.Context;
 import android.content.Intent;
 import android.graphics.BitmapFactory;
 import android.os.Binder;
@@ -42,13 +41,13 @@ import android.util.Pair;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.files.downloader.DownloadTask;
+import com.nextcloud.client.files.downloader.FilesDownloadWorker;
 import com.nextcloud.java.util.Optional;
-import com.nextcloud.utils.ForegroundServiceHelper;
 import com.nextcloud.utils.extensions.IntentExtensionsKt;
+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.UploadsStorageManager;
 import com.owncloud.android.lib.common.OwnCloudAccount;
@@ -86,16 +85,17 @@ import javax.inject.Inject;
 
 import androidx.core.app.NotificationCompat;
 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
-import dagger.android.AndroidInjection;
+import androidx.work.OneTimeWorkRequest;
+import androidx.work.WorkManager;
+import androidx.work.WorkRequest;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 
 import static android.content.Context.NOTIFICATION_SERVICE;
 
 public class FileDownloader implements OnDatatransferProgressListener, OnAccountsUpdateListener {
 
-    private final Activity activity;
+    private final Context context = MainApp.getAppContext();
     private final Intent intent;
-    private final int startId;
 
     public static final String EXTRA_USER = "USER";
     public static final String EXTRA_FILE = "FILE";
@@ -146,25 +146,21 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
         return FileDownloader.class.getName() + DOWNLOAD_FINISH_MESSAGE;
     }
 
-    public FileDownloader(Activity activity, Intent intent, int startId) {
-        this.activity = activity;
+    public FileDownloader(Intent intent) {
         this.intent = intent;
-        this.startId = startId;
-
-        AndroidInjection.inject(activity);
         Log_OC.d(TAG, "Creating service");
-        mNotificationManager = (NotificationManager) activity.getSystemService(NOTIFICATION_SERVICE);
+        mNotificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
         HandlerThread thread = new HandlerThread("FileDownloaderThread", Process.THREAD_PRIORITY_BACKGROUND);
         thread.start();
         mServiceLooper = thread.getLooper();
         mServiceHandler = new ServiceHandler(mServiceLooper, this);
         mBinder = new FileDownloaderBinder();
 
-        NotificationCompat.Builder builder = NotificationUtils.newNotificationBuilder(activity, viewThemeUtils).setContentTitle(
-                activity.getResources().getString(R.string.app_name))
-            .setContentText(activity.getResources().getString(R.string.foreground_service_download))
+        NotificationCompat.Builder builder = NotificationUtils.newNotificationBuilder(context, viewThemeUtils).setContentTitle(
+                context.getResources().getString(R.string.app_name))
+            .setContentText(context.getResources().getString(R.string.foreground_service_download))
             .setSmallIcon(R.drawable.notification_icon)
-            .setLargeIcon(BitmapFactory.decodeResource(activity.getResources(), R.drawable.notification_icon));
+            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.notification_icon));
 
 
         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
@@ -174,11 +170,10 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
         mNotification = builder.build();
 
         // add AccountsUpdatedListener
-        AccountManager am = AccountManager.get(activity);
+        AccountManager am = AccountManager.get(context);
         am.addOnAccountsUpdatedListener(this, null, false);
     }
 
-
     @Override
     protected void finalize() throws Throwable {
         Log_OC.v(TAG, "Destroying service");
@@ -189,7 +184,7 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
         mNotificationManager = null;
 
         // remove AccountsUpdatedListener
-        AccountManager am = AccountManager.get(activity);
+        AccountManager am = AccountManager.get(context);
         am.removeOnAccountsUpdatedListener(this);
         super.finalize();
     }
@@ -213,7 +208,7 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
                                                                           behaviour,
                                                                           activityName,
                                                                           packageName,
-                                                                          activity,
+                                                                          context,
                                                                           downloadType);
             newDownload.addDatatransferProgressListener(this);
             newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
@@ -232,7 +227,7 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
 
         if (requestedDownloads.size() > 0) {
             Message msg = mServiceHandler.obtainMessage();
-            msg.arg1 = startId;
+            // msg.arg1 = startId;
             msg.obj = requestedDownloads;
             mServiceHandler.sendMessage(msg);
         }
@@ -247,7 +242,6 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
         // The rest of downloads are cancelled when they try to start
     }
 
-
     /**
      * Binder to let client components to perform operations on the queue of downloads.
      * <p/>
@@ -296,11 +290,6 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
             cancelPendingDownloads(accountName);
         }
 
-        public void clearListeners() {
-            mBoundListeners.clear();
-        }
-
-
         /**
          * Returns True when the file described by 'file' in the ownCloud account 'account'
          * is downloading or waiting to download.
@@ -422,14 +411,14 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
                     Optional<User> currentDownloadUser = accountManager.getUser(currentDownloadAccount.name);
                     if (!currentUser.equals(currentDownloadUser)) {
                         currentUser = currentDownloadUser;
-                        mStorageManager = new FileDataStorageManager(currentUser.get(), activity.getContentResolver());
+                        mStorageManager = new FileDataStorageManager(currentUser.get(), context.getContentResolver());
                     }   // else, reuse storage manager from previous operation
 
                     // always get client from client manager, to get fresh credentials in case
                     // of update
                     OwnCloudAccount ocAccount = currentDownloadUser.get().toOwnCloudAccount();
                     mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
-                            getClientFor(ocAccount, activity);
+                            getClientFor(ocAccount, context);
 
 
                     /// perform the download
@@ -506,15 +495,15 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
     private void notifyDownloadStart(DownloadFileOperation download) {
         /// create status notification with a progress bar
         mLastPercent = 0;
-        mNotificationBuilder = NotificationUtils.newNotificationBuilder(activity, viewThemeUtils);
+        mNotificationBuilder = NotificationUtils.newNotificationBuilder(context, viewThemeUtils);
         mNotificationBuilder
             .setSmallIcon(R.drawable.notification_icon)
-            .setTicker(activity.getString(R.string.downloader_download_in_progress_ticker))
-            .setContentTitle(activity.getString(R.string.downloader_download_in_progress_ticker))
+            .setTicker(context.getString(R.string.downloader_download_in_progress_ticker))
+            .setContentTitle(context.getString(R.string.downloader_download_in_progress_ticker))
             .setOngoing(true)
             .setProgress(100, 0, download.getSize() < 0)
             .setContentText(
-                String.format(activity.getString(R.string.downloader_download_in_progress_content), 0,
+                String.format(context.getString(R.string.downloader_download_in_progress_content), 0,
                               new File(download.getSavePath()).getName()));
 
         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
@@ -524,20 +513,20 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
         /// includes a pending intent in the notification showing the details view of the file
         Intent showDetailsIntent = null;
         if (PreviewImageFragment.canBePreviewed(download.getFile())) {
-            showDetailsIntent = new Intent(activity, PreviewImageActivity.class);
+            showDetailsIntent = new Intent(context, PreviewImageActivity.class);
         } else {
-            showDetailsIntent = new Intent(activity, FileDisplayActivity.class);
+            showDetailsIntent = new Intent(context, FileDisplayActivity.class);
         }
         showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, download.getFile());
         showDetailsIntent.putExtra(FileActivity.EXTRA_USER, download.getUser());
         showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 
-        mNotificationBuilder.setContentIntent(PendingIntent.getActivity(activity, (int) System.currentTimeMillis(),
+        mNotificationBuilder.setContentIntent(PendingIntent.getActivity(context, (int) System.currentTimeMillis(),
                                                                         showDetailsIntent, PendingIntent.FLAG_IMMUTABLE));
 
 
         if (mNotificationManager == null) {
-            mNotificationManager = (NotificationManager) activity.getSystemService(NOTIFICATION_SERVICE);
+            mNotificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
         }
         if (mNotificationManager != null) {
             mNotificationManager.notify(R.string.downloader_download_in_progress_ticker, mNotificationBuilder.build());
@@ -555,11 +544,11 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
         if (percent != mLastPercent) {
             mNotificationBuilder.setProgress(100, percent, totalToTransfer < 0);
             String fileName = filePath.substring(filePath.lastIndexOf(FileUtils.PATH_SEPARATOR) + 1);
-            String text = String.format(activity.getString(R.string.downloader_download_in_progress_content), percent, fileName);
+            String text = String.format(context.getString(R.string.downloader_download_in_progress_content), percent, fileName);
             mNotificationBuilder.setContentText(text);
 
             if (mNotificationManager == null) {
-                mNotificationManager = (NotificationManager) activity.getSystemService(NOTIFICATION_SERVICE);
+                mNotificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
             }
 
             if (mNotificationManager != null) {
@@ -581,7 +570,7 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
     private void notifyDownloadResult(DownloadFileOperation download,
                                       RemoteOperationResult downloadResult) {
         if (mNotificationManager == null) {
-            mNotificationManager = (NotificationManager) activity.getSystemService(NOTIFICATION_SERVICE);
+            mNotificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
         }
 
         if (!downloadResult.isCancelled()) {
@@ -600,8 +589,8 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
                     R.string.downloader_download_failed_credentials_error : tickerId;
 
             mNotificationBuilder
-                    .setTicker(activity.getString(tickerId))
-                    .setContentTitle(activity.getString(tickerId))
+                    .setTicker(context.getString(tickerId))
+                    .setContentTitle(context.getString(tickerId))
                     .setAutoCancel(true)
                     .setOngoing(false)
                     .setProgress(0, 0, false);
@@ -612,12 +601,12 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
             } else {
                 // TODO put something smart in showDetailsIntent
                 Intent showDetailsIntent = new Intent();
-                mNotificationBuilder.setContentIntent(PendingIntent.getActivity(activity, (int) System.currentTimeMillis(),
+                mNotificationBuilder.setContentIntent(PendingIntent.getActivity(context, (int) System.currentTimeMillis(),
                                                                                 showDetailsIntent, PendingIntent.FLAG_IMMUTABLE));
             }
 
             mNotificationBuilder.setContentText(ErrorMessageAdapter.getErrorCauseMessage(downloadResult,
-                    download, activity.getResources()));
+                                                                                         download, context.getResources()));
 
             if (mNotificationManager != null) {
                 mNotificationManager.notify((new SecureRandom()).nextInt(), mNotificationBuilder.build());
@@ -634,7 +623,7 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
 
     private void configureUpdateCredentialsNotification(User user) {
         // let the user update credentials with one click
-        Intent updateAccountCredentials = new Intent(activity, AuthenticatorActivity.class);
+        Intent updateAccountCredentials = new Intent(context, AuthenticatorActivity.class);
         updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, user.toPlatformAccount());
         updateAccountCredentials.putExtra(
                 AuthenticatorActivity.EXTRA_ACTION,
@@ -644,7 +633,7 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
         updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
         updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
         mNotificationBuilder.setContentIntent(
-            PendingIntent.getActivity(activity,
+            PendingIntent.getActivity(context,
                                       (int) System.currentTimeMillis(),
                                       updateAccountCredentials,
                                       PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE)
@@ -675,7 +664,7 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
         if (unlinkedFromRemotePath != null) {
             end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath);
         }
-        end.setPackage(activity.getPackageName());
+        end.setPackage(context.getPackageName());
         localBroadcastManager.sendBroadcast(end);
     }
 
@@ -692,7 +681,7 @@ public class FileDownloader implements OnDatatransferProgressListener, OnAccount
         added.putExtra(ACCOUNT_NAME, download.getUser().getAccountName());
         added.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath());
         added.putExtra(EXTRA_LINKED_TO_PATH, linkedToRemotePath);
-        added.setPackage(activity.getPackageName());
+        added.setPackage(context.getPackageName());
         localBroadcastManager.sendBroadcast(added);
     }
 

+ 1 - 5
app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java

@@ -320,12 +320,8 @@ public class SynchronizeFileOperation extends SyncOperation {
         Intent i = new Intent(mContext, FileDownloader.class);
         i.putExtra(FileDownloader.EXTRA_USER, mUser);
         i.putExtra(FileDownloader.EXTRA_FILE, file);
-        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
-            mContext.startForegroundService(i);
-        } else {
-            mContext.startService(i);
-        }
 
+        new FileDownloader(i);
         mTransferWasRequested = true;
     }
 

+ 2 - 1
app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt

@@ -118,7 +118,8 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener
                     intent.putExtra(FileDownloader.EXTRA_USER, getUser().orElseThrow { RuntimeException() })
                     intent.putExtra(FileDownloader.EXTRA_FILE, file)
                     intent.putExtra(EXTRA_CONFLICT_UPLOAD_ID, conflictUploadId)
-                    startService(intent)
+
+                    FileDownloader(intent)
                 } else {
                     uploadsStorageManager!!.removeUpload(upload)
                 }

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

@@ -234,8 +234,7 @@ public abstract class FileActivity extends DrawerActivity
 
         mDownloadServiceConnection = newTransferenceServiceConnection();
         if (mDownloadServiceConnection != null) {
-            bindService(new Intent(this, FileDownloader.class), mDownloadServiceConnection,
-                    Context.BIND_AUTO_CREATE);
+            new FileDownloader(new Intent(this, FileDownloader.class));
         }
         mUploadServiceConnection = newTransferenceServiceConnection();
         if (mUploadServiceConnection != null) {

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

@@ -419,7 +419,7 @@ public class PreviewImageActivity extends FileActivity implements
             if (downloadBehaviour != null) {
                 i.putExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR, downloadBehaviour);
             }
-            startService(i);
+            new FileDownloader(i);
         }
     }
 

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java

@@ -482,7 +482,7 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
                 Intent i = new Intent(requireActivity(), FileDownloader.class);
                 i.putExtra(FileDownloader.EXTRA_USER, user);
                 i.putExtra(FileDownloader.EXTRA_FILE, getFile());
-                requireActivity().startService(i);
+                new FileDownloader(i);
             }
         }
     }