diff --git a/src/main/java/com/owncloud/android/MainApp.java b/src/main/java/com/owncloud/android/MainApp.java index d429b17dbe..0517508972 100644 --- a/src/main/java/com/owncloud/android/MainApp.java +++ b/src/main/java/com/owncloud/android/MainApp.java @@ -186,7 +186,7 @@ public class MainApp extends MultiDexApplication { initiateExistingAutoUploadEntries(); - FilesSyncHelper.scheduleFilesSyncIfNeeded(); + FilesSyncHelper.scheduleFilesSyncIfNeeded(mContext); FilesSyncHelper.restartJobsIfNeeded(); ReceiversHelper.registerNetworkChangeReceiver(); diff --git a/src/main/java/com/owncloud/android/jobs/NContentObserverJob.java b/src/main/java/com/owncloud/android/jobs/NContentObserverJob.java index 7e5fc85417..fa82768a3a 100644 --- a/src/main/java/com/owncloud/android/jobs/NContentObserverJob.java +++ b/src/main/java/com/owncloud/android/jobs/NContentObserverJob.java @@ -56,7 +56,7 @@ public class NContentObserverJob extends JobService { .schedule(); } - FilesSyncHelper.scheduleNJobs(true); + FilesSyncHelper.scheduleNJobs(true, getApplicationContext()); } return true; diff --git a/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java b/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java index 47c22b68a2..b039ad89ba 100644 --- a/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java @@ -502,7 +502,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + syncedFolderDisplayItem.getId(); arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey); } - FilesSyncHelper.scheduleNJobs(false); + FilesSyncHelper.scheduleNJobs(false, getApplicationContext()); } @@ -555,7 +555,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + newCustomFolder.getId(); arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey); } - FilesSyncHelper.scheduleNJobs(false); + FilesSyncHelper.scheduleNJobs(false, getApplicationContext()); } mAdapter.addSyncFolderItem(newCustomFolder); } else { @@ -575,7 +575,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId(); arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey); } - FilesSyncHelper.scheduleNJobs(false); + FilesSyncHelper.scheduleNJobs(false, getApplicationContext()); } } else { // existing synced folder setup to be updated @@ -586,7 +586,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId(); arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey); } - FilesSyncHelper.scheduleNJobs(false); + FilesSyncHelper.scheduleNJobs(false, getApplicationContext()); } mAdapter.setSyncFolderItem(syncedFolder.getSection(), item); diff --git a/src/main/java/com/owncloud/android/utils/FilesSyncHelper.java b/src/main/java/com/owncloud/android/utils/FilesSyncHelper.java index c92635153e..1031b24dab 100644 --- a/src/main/java/com/owncloud/android/utils/FilesSyncHelper.java +++ b/src/main/java/com/owncloud/android/utils/FilesSyncHelper.java @@ -253,9 +253,8 @@ public class FilesSyncHelper { return false; } - public static void scheduleNJobs(boolean force) { - SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(MainApp.getAppContext(). - getContentResolver()); + public static void scheduleNJobs(boolean force, Context context) { + SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver()); boolean hasVideoFolders = false; @@ -282,7 +281,7 @@ public class FilesSyncHelper { } } - public static void scheduleFilesSyncIfNeeded() { + public static void scheduleFilesSyncIfNeeded(Context context) { // always run this because it also allows us to perform retries of manual uploads new JobRequest.Builder(FilesSyncJob.TAG) .setPeriodic(900000L, 300000L) @@ -290,7 +289,9 @@ public class FilesSyncHelper { .build() .schedule(); - scheduleNJobs(false); + if (context != null) { + scheduleNJobs(false, context); + } } @RequiresApi(api = Build.VERSION_CODES.N)