From 329bccd51439705520e153cd53aec21ae4aa8e58 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 7 Sep 2017 17:48:04 +0200 Subject: [PATCH] Fix NPE Signed-off-by: Mario Danic --- src/main/java/com/owncloud/android/MainApp.java | 2 +- .../owncloud/android/jobs/NContentObserverJob.java | 2 +- .../android/ui/activity/SyncedFoldersActivity.java | 8 ++++---- .../com/owncloud/android/utils/FilesSyncHelper.java | 11 ++++++----- 4 files changed, 12 insertions(+), 11 deletions(-) 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)