diff --git a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt index 68b1e49b98e1..6201f0439ecd 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt @@ -173,4 +173,5 @@ interface BackgroundJobManager { fun startOfflineOperations() fun startPeriodicallyOfflineOperation() fun scheduleInternal2WaySync(intervalMinutes: Long) + fun cancelAllFilesDownloadJobs() } diff --git a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt index c208932d9686..076c60916137 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt @@ -507,6 +507,10 @@ internal class BackgroundJobManagerImpl( workManager.cancelJob(JOB_INTERNAL_TWO_WAY_SYNC) } + override fun cancelAllFilesDownloadJobs() { + workManager.cancelAllWorkByTag(formatClassTag(FileDownloadWorker::class)) + } + override fun scheduleOfflineSync() { val constrains = Constraints.Builder() .setRequiredNetworkType(NetworkType.UNMETERED) diff --git a/app/src/main/java/com/nextcloud/client/preferences/AppPreferences.java b/app/src/main/java/com/nextcloud/client/preferences/AppPreferences.java index 68c49eb4bedd..da116d53bfc5 100644 --- a/app/src/main/java/com/nextcloud/client/preferences/AppPreferences.java +++ b/app/src/main/java/com/nextcloud/client/preferences/AppPreferences.java @@ -397,4 +397,7 @@ default void onDarkThemeModeChanged(DarkMode mode) { void setTwoWaySyncInterval(Long value); Long getTwoWaySyncInterval(); + + boolean shouldStopDownloadJobsOnStart(); + void setStopDownloadJobsOnStart(boolean value); } diff --git a/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java b/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java index 50ee37e3f6c0..a20fd40be35a 100644 --- a/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java +++ b/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java @@ -105,6 +105,8 @@ public final class AppPreferencesImpl implements AppPreferences { private static final String PREF__TWO_WAY_STATUS = "two_way_sync_status"; private static final String PREF__TWO_WAY_SYNC_INTERVAL = "two_way_sync_interval"; + private static final String PREF__STOP_DOWNLOAD_JOBS_ON_START = "stop_download_jobs_on_start"; + private static final String LOG_ENTRY = "log_entry"; private final Context context; @@ -812,4 +814,14 @@ public void setTwoWaySyncInterval(Long value) { public Long getTwoWaySyncInterval() { return preferences.getLong(PREF__TWO_WAY_SYNC_INTERVAL, 15L); } + + @Override + public boolean shouldStopDownloadJobsOnStart() { + return preferences.getBoolean(PREF__STOP_DOWNLOAD_JOBS_ON_START, true); + } + + @Override + public void setStopDownloadJobsOnStart(boolean value) { + preferences.edit().putBoolean(PREF__STOP_DOWNLOAD_JOBS_ON_START, value).apply(); + } } diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index b0a44d1e44bd..08b52ea77671 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -326,6 +326,8 @@ public void onCreate() { fixStoragePath(); + checkCancelDownloadJobs(); + MainApp.storagePath = preferences.getStoragePath(getApplicationContext().getFilesDir().getAbsolutePath()); OwnCloudClientManagerFactory.setUserAgent(getUserAgent()); @@ -568,6 +570,13 @@ private void enableStrictMode() { } } + private void checkCancelDownloadJobs() { + if (backgroundJobManager != null && preferences.shouldStopDownloadJobsOnStart()) { + backgroundJobManager.cancelAllFilesDownloadJobs(); + preferences.setStopDownloadJobsOnStart(false); + } + } + public static void initSyncOperations( final Context context, final AppPreferences preferences,