From c02f79e05a0da2c2d80c6fe4ad9badea2a39c584 Mon Sep 17 00:00:00 2001 From: Chris Narkiewicz Date: Sun, 23 Jun 2019 22:51:03 +0100 Subject: [PATCH 1/2] Remove DI from NContentObserverJob Removing DI from the service fixes DI crash on older devices when JobService is not provided by the system, prevending ClassNotFoundException. A proper fix for this issue must follow. Signed-off-by: Chris Narkiewicz --- src/main/java/com/owncloud/android/MainApp.java | 16 ++++++++++++++++ .../android/jobs/NContentObserverJob.java | 15 +++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/owncloud/android/MainApp.java b/src/main/java/com/owncloud/android/MainApp.java index 75d40de8bc..a04d9017ea 100644 --- a/src/main/java/com/owncloud/android/MainApp.java +++ b/src/main/java/com/owncloud/android/MainApp.java @@ -175,6 +175,22 @@ public class MainApp extends MultiDexApplication implements mContext = context; } + /** + * Temporary getter replacing Dagger DI + * TODO: remove when cleaning DI in NContentObserverJob + */ + public AppPreferences getPreferences() { + return preferences; + } + + /** + * Temporary getter replacing Dagger DI + * TODO: remove when cleaning DI in NContentObserverJob + */ + public PowerManagementService getPowerManagementService() { + return powerManagementService; + } + @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); diff --git a/src/main/java/com/owncloud/android/jobs/NContentObserverJob.java b/src/main/java/com/owncloud/android/jobs/NContentObserverJob.java index fde69fb6e9..7d228ada08 100644 --- a/src/main/java/com/owncloud/android/jobs/NContentObserverJob.java +++ b/src/main/java/com/owncloud/android/jobs/NContentObserverJob.java @@ -29,13 +29,11 @@ import com.evernote.android.job.JobRequest; import com.evernote.android.job.util.support.PersistableBundleCompat; import com.nextcloud.client.device.PowerManagementService; import com.nextcloud.client.preferences.AppPreferences; +import com.owncloud.android.MainApp; import com.owncloud.android.datamodel.SyncedFolderProvider; import com.owncloud.android.utils.FilesSyncHelper; -import javax.inject.Inject; - import androidx.annotation.RequiresApi; -import dagger.android.AndroidInjection; /* Job that triggers new FilesSyncJob in case new photo or video were detected @@ -44,13 +42,18 @@ import dagger.android.AndroidInjection; @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public class NContentObserverJob extends JobService { - @Inject PowerManagementService powerManagementService; - @Inject AppPreferences preferences; + private PowerManagementService powerManagementService; + private AppPreferences preferences; @Override public void onCreate() { super.onCreate(); - AndroidInjection.inject(this); + + // Temporary workaround for https://github.com/nextcloud/android/issues/4147 + // TODO: this must be fixed properly + MainApp app = (MainApp) getApplication(); + powerManagementService = app.getPowerManagementService(); + preferences = app.getPreferences(); } @Override From e3fed8ddacd07d793f07d0d0bc00442b5c5bb26d Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 24 Jun 2019 21:33:13 +0200 Subject: [PATCH 2/2] remove also from DI Signed-off-by: tobiasKaminsky --- .../com/nextcloud/client/di/ComponentsModule.java | 4 ---- .../android/providers/DocumentsStorageProvider.java | 11 +++-------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/nextcloud/client/di/ComponentsModule.java b/src/main/java/com/nextcloud/client/di/ComponentsModule.java index 77573a7ec4..da0f0f820b 100644 --- a/src/main/java/com/nextcloud/client/di/ComponentsModule.java +++ b/src/main/java/com/nextcloud/client/di/ComponentsModule.java @@ -27,10 +27,8 @@ import com.owncloud.android.authentication.DeepLinkLoginActivity; import com.owncloud.android.files.BootupBroadcastReceiver; import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileUploader; -import com.owncloud.android.jobs.NContentObserverJob; import com.owncloud.android.jobs.NotificationJob; import com.owncloud.android.providers.DiskLruImageCacheFileProvider; -import com.owncloud.android.providers.DocumentsStorageProvider; import com.owncloud.android.providers.UsersAndGroupsSearchProvider; import com.owncloud.android.services.AccountManagerService; import com.owncloud.android.services.OperationsService; @@ -145,11 +143,9 @@ abstract class ComponentsModule { @ContributesAndroidInjector abstract BootupBroadcastReceiver bootupBroadcastReceiver(); @ContributesAndroidInjector abstract NotificationJob.NotificationReceiver notificationJobBroadcastReceiver(); - @ContributesAndroidInjector abstract DocumentsStorageProvider documentsStorageProvider(); @ContributesAndroidInjector abstract UsersAndGroupsSearchProvider usersAndGroupsSearchProvider(); @ContributesAndroidInjector abstract DiskLruImageCacheFileProvider diskLruImageCacheFileProvider(); @ContributesAndroidInjector abstract AccountManagerService accountManagerService(); @ContributesAndroidInjector abstract OperationsService operationsService(); - @ContributesAndroidInjector abstract NContentObserverJob contentObserverJob(); } diff --git a/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java b/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java index 751cb48f03..a0528a6137 100644 --- a/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java +++ b/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java @@ -46,6 +46,7 @@ import android.widget.Toast; import com.evernote.android.job.JobRequest; import com.evernote.android.job.util.Device; import com.nextcloud.client.account.UserAccountManager; +import com.nextcloud.client.account.UserAccountManagerImpl; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.AppPreferencesImpl; import com.owncloud.android.MainApp; @@ -84,10 +85,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.inject.Inject; - -import dagger.android.AndroidInjection; - import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR; import static com.owncloud.android.datamodel.OCFile.ROOT_PATH; @@ -100,9 +97,7 @@ public class DocumentsStorageProvider extends DocumentsProvider { private Map rootIdToStorageManager; private OwnCloudClient client; - @Inject UserAccountManager accountManager; - - + UserAccountManager accountManager; @Override public Cursor queryRoots(String[] projection) throws FileNotFoundException { @@ -301,7 +296,7 @@ public class DocumentsStorageProvider extends DocumentsProvider { @Override public boolean onCreate() { - AndroidInjection.inject(this); + accountManager = UserAccountManagerImpl.fromContext(getContext()); return true; }