Skip to content

Commit

Permalink
Clear download jobs on first start
Browse files Browse the repository at this point in the history
This will cancel all download jobs on first launch.

Signed-off-by: ZetaTom <[email protected]>
  • Loading branch information
ZetaTom committed Nov 12, 2024
1 parent ca29ea9 commit 7c3eb3d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,5 @@ interface BackgroundJobManager {
fun startOfflineOperations()
fun startPeriodicallyOfflineOperation()
fun scheduleInternal2WaySync(intervalMinutes: Long)
fun cancelAllFilesDownloadJobs()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,7 @@ default void onDarkThemeModeChanged(DarkMode mode) {

void setTwoWaySyncInterval(Long value);
Long getTwoWaySyncInterval();

boolean shouldStopDownloadJobsOnStart();
void setStopDownloadJobsOnStart(boolean value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ public void onCreate() {

fixStoragePath();

checkCancelDownloadJobs();

MainApp.storagePath = preferences.getStoragePath(getApplicationContext().getFilesDir().getAbsolutePath());

OwnCloudClientManagerFactory.setUserAgent(getUserAgent());
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7c3eb3d

Please sign in to comment.