From c2c2d0b21e12b73a2a8444f53fdfbf9843190c92 Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 17 Jun 2019 18:17:37 +0200 Subject: [PATCH] Dagger: make SDK DI working --- .../im/vector/matrix/android/api/Matrix.kt | 4 + .../matrix/android/internal/SessionManager.kt | 24 +- .../android/internal/auth/AuthModule.kt | 12 +- .../internal/auth/DefaultAuthenticator.kt | 4 +- .../auth/db/RealmSessionParamsStore.kt | 6 +- .../android/internal/crypto/CryptoManager.kt | 3 +- .../android/internal/crypto/CryptoModule.kt | 220 +++++++++++++++--- .../android/internal/di/DbQualifiers.kt | 31 +++ .../internal/di/MatrixAssistedInjectModule.kt | 26 --- .../internal/di/MatrixAssistedModule.kt | 24 ++ .../android/internal/di/MatrixComponent.kt | 27 ++- .../android/internal/di/MatrixModule.kt | 26 ++- .../android/internal/di/NetworkModule.kt | 16 +- .../internal/session/DefaultSession.kt | 41 ++-- .../internal/session/SessionComponent.kt | 37 +-- .../android/internal/session/SessionModule.kt | 116 +++++---- .../internal/session/cache/CacheModule.kt | 19 +- ...almClearCacheTask.kt => ClearCacheTask.kt} | 3 +- .../session/cache/DefaultCacheService.kt | 3 +- .../session/content/UploadContentWorker.kt | 2 +- .../session/filter/DefaultFilterRepository.kt | 5 +- .../session/group/GetGroupDataWorker.kt | 12 +- .../session/group/GroupSummaryUpdater.kt | 2 +- .../internal/session/room/RoomModule.kt | 6 + .../session/room/create/CreateRoomTask.kt | 3 +- .../session/room/prune/EventsPruner.kt | 3 +- .../room/relation/DefaultRelationService.kt | 4 +- .../room/relation/SendRelationWorker.kt | 2 +- .../session/room/send/DefaultSendService.kt | 2 +- .../session/room/send/EncryptEventWorker.kt | 4 +- .../session/room/send/RedactEventWorker.kt | 4 +- .../session/room/send/SendEventWorker.kt | 2 +- .../session/sync/ReadReceiptHandler.kt | 3 +- .../internal/session/sync/SyncTokenStore.kt | 3 +- .../android/internal/task/TaskExecutor.kt | 15 +- .../util/BackgroundDetectionObserver.kt | 5 +- .../android/internal/util/StringProvider.kt | 3 +- .../internal/worker/DelegateWorkerFactory.kt | 2 +- .../internal/worker/MatrixWorkerFactory.kt | 1 - .../worker/{DI.kt => WorkerBindingModule.kt} | 7 - .../android/internal/worker/WorkerKey.kt | 26 +++ .../{util => worker}/WorkerParamsFactory.kt | 2 +- 42 files changed, 544 insertions(+), 216 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/DbQualifiers.kt delete mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixAssistedInjectModule.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixAssistedModule.kt rename matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/{RealmClearCacheTask.kt => ClearCacheTask.kt} (88%) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/{DI.kt => WorkerBindingModule.kt} (89%) create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerKey.kt rename matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/{util => worker}/WorkerParamsFactory.kt (96%) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt index 9f99088904..c4d128ea66 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt @@ -22,8 +22,10 @@ import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.auth.Authenticator import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.sync.FilterService +import im.vector.matrix.android.internal.di.DaggerMatrixComponent import im.vector.matrix.android.internal.network.UserAgentHolder import im.vector.matrix.android.internal.util.BackgroundDetectionObserver +import org.matrix.olm.OlmManager import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject @@ -34,6 +36,7 @@ import javax.inject.Inject */ class Matrix private constructor(context: Context) { + @Inject internal lateinit var olmManager: OlmManager @Inject internal lateinit var authenticator: Authenticator @Inject internal lateinit var userAgentHolder: UserAgentHolder @Inject internal lateinit var backgroundDetectionObserver: BackgroundDetectionObserver @@ -41,6 +44,7 @@ class Matrix private constructor(context: Context) { init { Monarchy.init(context) + DaggerMatrixComponent.factory().create(context).inject(this) ProcessLifecycleOwner.get().lifecycle.addObserver(backgroundDetectionObserver) authenticator.getLastActiveSession()?.also { currentSession = it diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt index b46e4b78f5..74124bba6c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt @@ -18,25 +18,41 @@ package im.vector.matrix.android.internal +import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.session.Session +import im.vector.matrix.android.internal.di.MatrixComponent import im.vector.matrix.android.internal.di.MatrixScope +import im.vector.matrix.android.internal.session.DaggerSessionComponent import im.vector.matrix.android.internal.session.SessionComponent import javax.inject.Inject @MatrixScope -internal class SessionManager @Inject constructor() { +internal class SessionManager @Inject constructor(private val matrixComponent: MatrixComponent) { private val sessionComponents = HashMap() - private val sessions = HashMap() - fun createSession(userId: String): Session? { + fun createSession(sessionParams: SessionParams): Session { + val userId = sessionParams.credentials.userId if (sessionComponents.containsKey(userId)) { throw RuntimeException("You already have a session for the user $userId") } - return null + return DaggerSessionComponent + .factory() + .create(matrixComponent, sessionParams) + .also { + sessionComponents[userId] = it + }.let { + it.session() + } } fun releaseSession(userId: String) { + if (sessionComponents.containsKey(userId).not()) { + throw RuntimeException("You don't have a session for the user $userId") + } + sessionComponents.remove(userId)?.also { + it.session().close() + } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthModule.kt index 1e11a3c329..2f7746475f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthModule.kt @@ -20,24 +20,23 @@ import android.content.Context import dagger.Binds import dagger.Module import dagger.Provides +import im.vector.matrix.android.api.auth.Authenticator import im.vector.matrix.android.internal.auth.db.AuthRealmModule import im.vector.matrix.android.internal.auth.db.RealmSessionParamsStore +import im.vector.matrix.android.internal.di.AuthDatabase import im.vector.matrix.android.internal.di.MatrixScope -import im.vector.matrix.android.internal.session.SessionScope -import im.vector.matrix.android.internal.session.cache.ClearCacheTask -import im.vector.matrix.android.internal.session.cache.RealmClearCacheTask import io.realm.RealmConfiguration import java.io.File -import javax.inject.Named @Module internal abstract class AuthModule { @Module companion object { + @JvmStatic @Provides @MatrixScope - @Named("AuthRealmConfiguration") + @AuthDatabase fun providesRealmConfiguration(context: Context): RealmConfiguration { val old = File(context.filesDir, "matrix-sdk-auth") if (old.exists()) { @@ -55,5 +54,8 @@ internal abstract class AuthModule { @MatrixScope abstract fun bindSessionParamsStore(sessionParamsStore: RealmSessionParamsStore): SessionParamsStore + @Binds + @MatrixScope + abstract fun bindAuthenticator(authenticator: DefaultAuthenticator): Authenticator } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt index 4acd980075..56571fa8ce 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt @@ -51,7 +51,7 @@ internal class DefaultAuthenticator @Inject constructor(private val retrofitBuil override fun getLastActiveSession(): Session? { val sessionParams = sessionParamsStore.get() return sessionParams?.let { - sessionManager.createSession(it.credentials.userId) + sessionManager.createSession(it) } } @@ -85,7 +85,7 @@ internal class DefaultAuthenticator @Inject constructor(private val retrofitBuil sessionParamsStore.save(sessionParams) sessionParams }.map { - sessionManager.createSession(it.credentials.userId)!! + sessionManager.createSession(it) } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt index 94b86a18bc..3b742e6551 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt @@ -19,16 +19,16 @@ package im.vector.matrix.android.internal.auth.db import arrow.core.Try import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.internal.auth.SessionParamsStore +import im.vector.matrix.android.internal.di.AuthDatabase import im.vector.matrix.android.internal.di.MatrixScope import io.realm.Realm import io.realm.RealmConfiguration import javax.inject.Inject -import javax.inject.Named @MatrixScope internal class RealmSessionParamsStore @Inject constructor(private val mapper: SessionParamsMapper, - @Named("AuthRealmConfiguration") - private val realmConfiguration: RealmConfiguration) : SessionParamsStore { + @AuthDatabase private val realmConfiguration: RealmConfiguration +) : SessionParamsStore { override fun save(sessionParams: SessionParams): Try { return Try { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt index 8b60b5c049..4c011bfd4f 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt @@ -60,6 +60,7 @@ import im.vector.matrix.android.internal.crypto.tasks.GetDevicesTask import im.vector.matrix.android.internal.crypto.tasks.SetDeviceNameTask import im.vector.matrix.android.internal.crypto.tasks.UploadKeysTask import im.vector.matrix.android.internal.crypto.verification.DefaultSasVerificationService +import im.vector.matrix.android.internal.di.CryptoDatabase import im.vector.matrix.android.internal.database.model.EventEntity import im.vector.matrix.android.internal.database.query.where import im.vector.matrix.android.internal.di.MoshiProvider @@ -132,7 +133,7 @@ internal class CryptoManager @Inject constructor( private val setDeviceNameTask: SetDeviceNameTask, private val uploadKeysTask: UploadKeysTask, private val loadRoomMembersTask: LoadRoomMembersTask, - private val clearCryptoDataTask: ClearCacheTask, + @CryptoDatabase private val clearCryptoDataTask: ClearCacheTask, private val monarchy: Monarchy, private val coroutineDispatchers: MatrixCoroutineDispatchers, private val taskExecutor: TaskExecutor diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt index acb8045d86..ccaa6c56a6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt @@ -17,65 +17,219 @@ package im.vector.matrix.android.internal.crypto import android.content.Context +import dagger.Binds import dagger.Module import dagger.Provides import im.vector.matrix.android.api.auth.data.Credentials +import im.vector.matrix.android.api.session.crypto.CryptoService import im.vector.matrix.android.internal.crypto.api.CryptoApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.CreateKeysBackupVersionTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultCreateKeysBackupVersionTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultDeleteBackupTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultDeleteRoomSessionDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultDeleteRoomSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultDeleteSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultGetKeysBackupLastVersionTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultGetKeysBackupVersionTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultGetRoomSessionDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultGetRoomSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultGetSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultStoreRoomSessionDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultStoreRoomSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultStoreSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DefaultUpdateKeysBackupVersionTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DeleteBackupTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DeleteRoomSessionDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DeleteRoomSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.DeleteSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.GetKeysBackupLastVersionTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.GetKeysBackupVersionTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.GetRoomSessionDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.GetRoomSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.GetSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.StoreRoomSessionDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.StoreRoomSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.StoreSessionsDataTask +import im.vector.matrix.android.internal.crypto.keysbackup.tasks.UpdateKeysBackupVersionTask import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.store.db.RealmCryptoStore import im.vector.matrix.android.internal.crypto.store.db.RealmCryptoStoreMigration import im.vector.matrix.android.internal.crypto.store.db.RealmCryptoStoreModule import im.vector.matrix.android.internal.crypto.store.db.hash +import im.vector.matrix.android.internal.crypto.tasks.ClaimOneTimeKeysForUsersDeviceTask +import im.vector.matrix.android.internal.crypto.tasks.DefaultClaimOneTimeKeysForUsersDevice +import im.vector.matrix.android.internal.crypto.tasks.DefaultDeleteDeviceTask +import im.vector.matrix.android.internal.crypto.tasks.DefaultDownloadKeysForUsers +import im.vector.matrix.android.internal.crypto.tasks.DefaultGetDevicesTask +import im.vector.matrix.android.internal.crypto.tasks.DefaultSendToDeviceTask +import im.vector.matrix.android.internal.crypto.tasks.DefaultSetDeviceNameTask +import im.vector.matrix.android.internal.crypto.tasks.DefaultUploadKeysTask +import im.vector.matrix.android.internal.crypto.tasks.DeleteDeviceTask +import im.vector.matrix.android.internal.crypto.tasks.DownloadKeysForUsersTask +import im.vector.matrix.android.internal.crypto.tasks.GetDevicesTask +import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask +import im.vector.matrix.android.internal.crypto.tasks.SetDeviceNameTask +import im.vector.matrix.android.internal.crypto.tasks.UploadKeysTask +import im.vector.matrix.android.internal.di.CryptoDatabase import im.vector.matrix.android.internal.session.SessionScope +import im.vector.matrix.android.internal.session.cache.ClearCacheTask +import im.vector.matrix.android.internal.session.cache.RealmClearCacheTask import io.realm.RealmConfiguration import retrofit2.Retrofit import java.io.File -import javax.inject.Named @Module -internal class CryptoModule { +internal abstract class CryptoModule { + + @Module + companion object { + + // Realm configuration, named to avoid clash with main cache realm configuration + @JvmStatic + @Provides + @SessionScope + @CryptoDatabase + fun providesRealmConfiguration(context: Context, credentials: Credentials): RealmConfiguration { + return RealmConfiguration.Builder() + .directory(File(context.filesDir, credentials.userId.hash())) + .name("crypto_store.realm") + .modules(RealmCryptoStoreModule()) + .schemaVersion(RealmCryptoStoreMigration.CRYPTO_STORE_SCHEMA_VERSION) + .migration(RealmCryptoStoreMigration) + .build() + } + + @JvmStatic + @Provides + @SessionScope + @CryptoDatabase + fun providesClearCacheTask(@CryptoDatabase realmConfiguration: RealmConfiguration): ClearCacheTask { + return RealmClearCacheTask(realmConfiguration) + } + + + @JvmStatic + @Provides + @SessionScope + fun providesCryptoStore(@CryptoDatabase realmConfiguration: RealmConfiguration, credentials: Credentials): IMXCryptoStore { + return RealmCryptoStore(false /* TODO*/, + realmConfiguration, + credentials) + } + + @JvmStatic + @Provides + @SessionScope + fun providesCryptoAPI(retrofit: Retrofit): CryptoApi { + return retrofit.create(CryptoApi::class.java) + } + + @JvmStatic + @Provides + @SessionScope + fun providesRoomKeysAPI(retrofit: Retrofit): RoomKeysApi { + return retrofit.create(RoomKeysApi::class.java) + } + + @JvmStatic + @Provides + @SessionScope + fun providesCryptoConfig(): MXCryptoConfig { + return MXCryptoConfig() + } - // Realm configuration, named to avoid clash with main cache realm configuration - @Provides - @SessionScope - @Named("CryptonRealmConfiguration") - fun providesRealmConfiguration(context: Context, credentials: Credentials): RealmConfiguration { - return RealmConfiguration.Builder() - .directory(File(context.filesDir, credentials.userId.hash())) - .name("crypto_store.realm") - .modules(RealmCryptoStoreModule()) - .schemaVersion(RealmCryptoStoreMigration.CRYPTO_STORE_SCHEMA_VERSION) - .migration(RealmCryptoStoreMigration) - .build() } - @Provides + @Binds @SessionScope - fun providesCryptoStore(@Named("CryptonRealmConfiguration") - realmConfiguration: RealmConfiguration, credentials: Credentials): IMXCryptoStore { - return RealmCryptoStore(false /* TODO*/, - realmConfiguration, - credentials) - } + abstract fun bindCryptoService(cryptoManager: CryptoManager): CryptoService - @Provides + @Binds @SessionScope - fun providesCryptoAPI(retrofit: Retrofit): CryptoApi { - return retrofit.create(CryptoApi::class.java) - } + abstract fun bindDeleteDeviceTask(deleteDeviceTask: DefaultDeleteDeviceTask): DeleteDeviceTask - @Provides + @Binds @SessionScope - fun providesRoomKeysAPI(retrofit: Retrofit): RoomKeysApi { - return retrofit.create(RoomKeysApi::class.java) - } + abstract fun bindGetDevicesTask(getDevicesTask: DefaultGetDevicesTask): GetDevicesTask - @Provides + @Binds @SessionScope - fun providesCryptoConfig(): MXCryptoConfig { - return MXCryptoConfig() - } + abstract fun bindSetDeviceNameTask(getDevicesTask: DefaultSetDeviceNameTask): SetDeviceNameTask + + @Binds + @SessionScope + abstract fun bindUploadKeysTask(getDevicesTask: DefaultUploadKeysTask): UploadKeysTask + + @Binds + @SessionScope + abstract fun bindDownloadKeysForUsersTask(downloadKeysForUsers: DefaultDownloadKeysForUsers): DownloadKeysForUsersTask + + @Binds + @SessionScope + abstract fun bindCreateKeysBackupVersionTask(createKeysBackupVersionTask: DefaultCreateKeysBackupVersionTask): CreateKeysBackupVersionTask + + @Binds + @SessionScope + abstract fun bindDeleteBackupTask(deleteBackupTask: DefaultDeleteBackupTask): DeleteBackupTask + + @Binds + @SessionScope + abstract fun bindDeleteRoomSessionDataTask(deleteRoomSessionDataTask: DefaultDeleteRoomSessionDataTask): DeleteRoomSessionDataTask + + @Binds + @SessionScope + abstract fun bindDeleteRoomSessionsDataTask(deleteRoomSessionDataTask: DefaultDeleteRoomSessionsDataTask): DeleteRoomSessionsDataTask + + @Binds + @SessionScope + abstract fun bindDeleteSessionsDataTask(deleteRoomSessionDataTask: DefaultDeleteSessionsDataTask): DeleteSessionsDataTask + + @Binds + @SessionScope + abstract fun bindGetKeysBackupLastVersionTask(getKeysBackupLastVersionTask: DefaultGetKeysBackupLastVersionTask): GetKeysBackupLastVersionTask + + @Binds + @SessionScope + abstract fun bindGetKeysBackupVersionTask(getKeysBackupVersionTask: DefaultGetKeysBackupVersionTask) : GetKeysBackupVersionTask + + @Binds + @SessionScope + abstract fun bindGetRoomSessionDataTask(getRoomSessionDataTask: DefaultGetRoomSessionDataTask) : GetRoomSessionDataTask + + @Binds + @SessionScope + abstract fun bindGetRoomSessionsDataTask(getRoomSessionDataTask: DefaultGetRoomSessionsDataTask) : GetRoomSessionsDataTask + + @Binds + @SessionScope + abstract fun bindGetSessionsDataTask(getRoomSessionDataTask: DefaultGetSessionsDataTask) : GetSessionsDataTask + + @Binds + @SessionScope + abstract fun bindStoreRoomSessionDataTask(storeRoomSessionDataTask: DefaultStoreRoomSessionDataTask) : StoreRoomSessionDataTask + + @Binds + @SessionScope + abstract fun bindStoreRoomSessionsDataTask(storeRoomSessionDataTask: DefaultStoreRoomSessionsDataTask) : StoreRoomSessionsDataTask + + @Binds + @SessionScope + abstract fun bindStoreSessionsDataTask(storeRoomSessionDataTask: DefaultStoreSessionsDataTask) : StoreSessionsDataTask + + @Binds + @SessionScope + abstract fun bindUpdateKeysBackupVersionTask(updateKeysBackupVersionTask: DefaultUpdateKeysBackupVersionTask) : UpdateKeysBackupVersionTask + + @Binds + @SessionScope + abstract fun bindSendToDeviceTask(sendToDeviceTask: DefaultSendToDeviceTask) : SendToDeviceTask + + @Binds + @SessionScope + abstract fun bindClaimOneTimeKeysForUsersDeviceTask(claimOneTimeKeysForUsersDevice: DefaultClaimOneTimeKeysForUsersDevice) : ClaimOneTimeKeysForUsersDeviceTask + + } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/DbQualifiers.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/DbQualifiers.kt new file mode 100644 index 0000000000..ac9a30a3ec --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/DbQualifiers.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.internal.di + +import javax.inject.Qualifier + +@Qualifier +@Retention(AnnotationRetention.RUNTIME) +annotation class AuthDatabase + +@Qualifier +@Retention(AnnotationRetention.RUNTIME) +annotation class SessionDatabase + +@Qualifier +@Retention(AnnotationRetention.RUNTIME) +annotation class CryptoDatabase \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixAssistedInjectModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixAssistedInjectModule.kt deleted file mode 100644 index 8f5723d078..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixAssistedInjectModule.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * * Copyright 2019 New Vector Ltd - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package im.vector.matrix.android.internal.di - -import com.squareup.inject.assisted.dagger2.AssistedModule -import dagger.Module - -@Module(includes = [AssistedInject_MatrixAssistedInjectModule::class]) -@AssistedModule -internal interface MatrixAssistedInjectModule \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixAssistedModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixAssistedModule.kt new file mode 100644 index 0000000000..ce1804cb6c --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixAssistedModule.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.internal.di + +import com.squareup.inject.assisted.dagger2.AssistedModule +import dagger.Module + +@Module(includes = [AssistedInject_MatrixAssistedModule::class]) +@AssistedModule +internal class MatrixAssistedModule \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixComponent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixComponent.kt index aa91eadca5..8517a4b366 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixComponent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixComponent.kt @@ -17,17 +17,24 @@ package im.vector.matrix.android.internal.di import android.content.Context +import android.content.res.Resources import com.squareup.moshi.Moshi import dagger.BindsInstance import dagger.Component +import im.vector.matrix.android.api.Matrix +import im.vector.matrix.android.api.auth.Authenticator import im.vector.matrix.android.internal.auth.AuthModule +import im.vector.matrix.android.internal.auth.SessionParamsStore +import im.vector.matrix.android.internal.network.NetworkConnectivityChecker +import im.vector.matrix.android.internal.task.TaskExecutor +import im.vector.matrix.android.internal.util.BackgroundDetectionObserver import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import im.vector.matrix.android.internal.worker.WorkerBindingModule +import org.matrix.olm.OlmManager import retrofit2.Retrofit -import java.net.Authenticator -@Component(modules = [MatrixModule::class, NetworkModule::class, AuthModule::class]) +@Component(modules = [MatrixModule::class, NetworkModule::class, AuthModule::class, WorkerBindingModule::class]) @MatrixScope internal interface MatrixComponent { @@ -39,6 +46,22 @@ internal interface MatrixComponent { fun authenticator(): Authenticator + fun context(): Context + + fun resources(): Resources + + fun olmManager(): OlmManager + + fun taskExecutor(): TaskExecutor + + fun sessionParamsStore(): SessionParamsStore + + fun networkConnectivityChecker(): NetworkConnectivityChecker + + fun backgroundDetectionObserver(): BackgroundDetectionObserver + + fun inject(matrix: Matrix) + @Component.Factory interface Factory { fun create(@BindsInstance context: Context): MatrixComponent diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt index b2bbefd528..a409c3d943 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt @@ -16,25 +16,43 @@ package im.vector.matrix.android.internal.di +import android.content.Context +import android.content.res.Resources import dagger.Module import dagger.Provides import im.vector.matrix.android.internal.crypto.CryptoAsyncHelper import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.android.asCoroutineDispatcher +import org.matrix.olm.OlmManager @Module -internal class MatrixModule { +internal object MatrixModule { + @JvmStatic @Provides @MatrixScope fun providesMatrixCoroutineDispatchers(): MatrixCoroutineDispatchers { val cryptoHandler = CryptoAsyncHelper.getDecryptBackgroundHandler() return MatrixCoroutineDispatchers(io = Dispatchers.IO, - computation = Dispatchers.IO, - main = Dispatchers.Main, - crypto = cryptoHandler.asCoroutineDispatcher("crypto") + computation = Dispatchers.IO, + main = Dispatchers.Main, + crypto = cryptoHandler.asCoroutineDispatcher("crypto") ) } + @JvmStatic + @Provides + @MatrixScope + fun providesResources(context: Context): Resources { + return context.resources + } + + @JvmStatic + @Provides + @MatrixScope + fun providesOlmManager(): OlmManager { + return OlmManager() + } + } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/NetworkModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/NetworkModule.kt index b11e5a1ec7..ed99dad378 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/NetworkModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/NetworkModule.kt @@ -34,10 +34,11 @@ import retrofit2.converter.moshi.MoshiConverterFactory import java.util.concurrent.TimeUnit @Module -internal class NetworkModule { +internal object NetworkModule { @MatrixScope @Provides + @JvmStatic fun providesHttpLogingInterceptor(): HttpLoggingInterceptor { val logger = FormattedJsonHttpLogger() val interceptor = HttpLoggingInterceptor(logger) @@ -47,18 +48,28 @@ internal class NetworkModule { @MatrixScope @Provides + @JvmStatic fun providesOkReplayInterceptor(): OkReplayInterceptor { return OkReplayInterceptor() } @MatrixScope @Provides + @JvmStatic fun providesStethoInterceptor(): StethoInterceptor { return StethoInterceptor() } @MatrixScope @Provides + @JvmStatic + fun providesCurlLoggingInterceptor(): CurlLoggingInterceptor { + return CurlLoggingInterceptor(HttpLoggingInterceptor.Logger.DEFAULT) + } + + @MatrixScope + @Provides + @JvmStatic fun providesOkHttpClient(stethoInterceptor: StethoInterceptor, userAgentInterceptor: UserAgentInterceptor, accessTokenInterceptor: AccessTokenInterceptor, @@ -84,11 +95,14 @@ internal class NetworkModule { @MatrixScope @Provides + @JvmStatic fun providesMoshi(): Moshi { return MoshiProvider.providesMoshi() } + @MatrixScope @Provides + @JvmStatic fun providesRetrofitBuilder(okHttpClient: OkHttpClient, moshi: Moshi): Retrofit.Builder { return Retrofit.Builder() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt index ec272083a3..fcc3d5bbc2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt @@ -19,8 +19,6 @@ package im.vector.matrix.android.internal.session import android.os.Looper import androidx.annotation.MainThread import androidx.lifecycle.LiveData -import com.squareup.inject.assisted.Assisted -import com.squareup.inject.assisted.AssistedInject import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.auth.data.SessionParams @@ -41,23 +39,23 @@ import im.vector.matrix.android.internal.crypto.CryptoManager import im.vector.matrix.android.internal.database.LiveEntityObserver import im.vector.matrix.android.internal.session.sync.job.SyncThread import timber.log.Timber +import javax.inject.Inject @SessionScope -internal class DefaultSession @AssistedInject constructor(@Assisted override val sessionParams: SessionParams, - private val monarchy: Monarchy, - private val liveEntityUpdaters: List, - private val sessionListeners: SessionListeners, - private val roomService: RoomService, - private val roomDirectoryService: RoomDirectoryService, - private val groupService: GroupService, - private val userService: UserService, - private val filterService: FilterService, - private val cacheService: CacheService, - private val signOutService: SignOutService, - private val cryptoService: CryptoManager, - private val syncThread: SyncThread, - private val contentUrlResolver: ContentUrlResolver, - private val contentUploadProgressTracker: ContentUploadStateTracker) +internal class DefaultSession @Inject constructor(override val sessionParams: SessionParams, + private val monarchy: Monarchy, + private val sessionListeners: SessionListeners, + private val roomService: RoomService, + private val roomDirectoryService: RoomDirectoryService, + private val groupService: GroupService, + private val userService: UserService, + private val filterService: FilterService, + private val cacheService: CacheService, + private val signOutService: SignOutService, + private val cryptoService: CryptoManager, + private val syncThread: SyncThread, + private val contentUrlResolver: ContentUrlResolver, + private val contentUploadProgressTracker: ContentUploadStateTracker) : Session, RoomService by roomService, RoomDirectoryService by roomDirectoryService, @@ -68,11 +66,6 @@ internal class DefaultSession @AssistedInject constructor(@Assisted override val SignOutService by signOutService, FilterService by filterService { - @AssistedInject.Factory - interface Factory { - fun create(sessionParams: SessionParams): DefaultSession - } - private var isOpen = false @MainThread @@ -83,7 +76,7 @@ internal class DefaultSession @AssistedInject constructor(@Assisted override val if (!monarchy.isMonarchyThreadOpen) { monarchy.openManually() } - liveEntityUpdaters.forEach { it.start() } + //liveEntityObservers.forEach { it.start() } } @MainThread @@ -102,7 +95,7 @@ internal class DefaultSession @AssistedInject constructor(@Assisted override val override fun close() { assertMainThread() assert(isOpen) - liveEntityUpdaters.forEach { it.dispose() } + //liveEntityObservers.forEach { it.dispose() } cryptoService.close() if (monarchy.isMonarchyThreadOpen) { monarchy.closeManually() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionComponent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionComponent.kt index 1283f3b09b..96419e6e59 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionComponent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionComponent.kt @@ -19,37 +19,40 @@ package im.vector.matrix.android.internal.session import dagger.BindsInstance import dagger.Component import im.vector.matrix.android.api.auth.data.SessionParams +import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.internal.crypto.CryptoModule -import im.vector.matrix.android.internal.di.MatrixAssistedInjectModule +import im.vector.matrix.android.internal.di.MatrixAssistedModule import im.vector.matrix.android.internal.di.MatrixComponent -import im.vector.matrix.android.internal.session.content.ContentModule import im.vector.matrix.android.internal.session.cache.CacheModule +import im.vector.matrix.android.internal.session.content.ContentModule import im.vector.matrix.android.internal.session.filter.FilterModule import im.vector.matrix.android.internal.session.group.GroupModule import im.vector.matrix.android.internal.session.room.RoomModule import im.vector.matrix.android.internal.session.signout.SignOutModule import im.vector.matrix.android.internal.session.sync.SyncModule -import im.vector.matrix.android.internal.worker.WorkerBindingModule +import im.vector.matrix.android.internal.session.user.UserModule @Component(dependencies = [MatrixComponent::class], - modules = [ - SessionModule::class, - RoomModule::class, - SyncModule::class, - SignOutModule::class, - GroupModule::class, - FilterModule::class, - GroupModule::class, - ContentModule::class, - CacheModule::class, - CryptoModule::class, - MatrixAssistedInjectModule::class, - WorkerBindingModule::class - ] + modules = [ + SessionModule::class, + RoomModule::class, + SyncModule::class, + SignOutModule::class, + GroupModule::class, + UserModule::class, + FilterModule::class, + GroupModule::class, + ContentModule::class, + CacheModule::class, + CryptoModule::class, + MatrixAssistedModule::class + ] ) @SessionScope internal interface SessionComponent { + fun session(): Session + @Component.Factory interface Factory { fun create( diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt index e68cd80970..4c5a2c0ced 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt @@ -18,13 +18,17 @@ package im.vector.matrix.android.internal.session import android.content.Context import com.zhuinden.monarchy.Monarchy +import dagger.Binds import dagger.Module import dagger.Provides +import dagger.multibindings.IntoSet import im.vector.matrix.android.api.auth.data.Credentials +import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig import im.vector.matrix.android.api.auth.data.SessionParams +import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.internal.database.LiveEntityObserver import im.vector.matrix.android.internal.database.model.SessionRealmModule -import im.vector.matrix.android.internal.session.filter.FilterApi +import im.vector.matrix.android.internal.di.SessionDatabase import im.vector.matrix.android.internal.session.group.GroupSummaryUpdater import im.vector.matrix.android.internal.session.room.EventRelationsAggregationUpdater import im.vector.matrix.android.internal.session.room.prune.EventsPruner @@ -33,62 +37,86 @@ import im.vector.matrix.android.internal.util.md5 import io.realm.RealmConfiguration import retrofit2.Retrofit import java.io.File -import javax.inject.Named @Module -internal object SessionModule { +internal abstract class SessionModule { - @Provides - @SessionScope - fun providesCredentials(sessionParams: SessionParams): Credentials { - return sessionParams.credentials + @Module + companion object { + + @JvmStatic + @Provides + @SessionScope + fun providesHomeServerConnectionConfig(sessionParams: SessionParams): HomeServerConnectionConfig { + return sessionParams.homeServerConnectionConfig + } + + + @JvmStatic + @Provides + @SessionScope + fun providesCredentials(sessionParams: SessionParams): Credentials { + return sessionParams.credentials + } + + @JvmStatic + @Provides + @SessionScope + @SessionDatabase + fun providesRealmConfiguration(sessionParams: SessionParams, context: Context): RealmConfiguration { + val childPath = sessionParams.credentials.userId.md5() + val directory = File(context.filesDir, childPath) + + return RealmConfiguration.Builder() + .directory(directory) + .name("disk_store.realm") + .modules(SessionRealmModule()) + .deleteRealmIfMigrationNeeded() + .build() + } + + @JvmStatic + @Provides + @SessionScope + fun providesMonarchy(@SessionDatabase + realmConfiguration: RealmConfiguration): Monarchy { + return Monarchy.Builder() + .setRealmConfiguration(realmConfiguration) + .build() + } + + @JvmStatic + @Provides + @SessionScope + fun providesRetrofit(sessionParams: SessionParams, retrofitBuilder: Retrofit.Builder): Retrofit { + return retrofitBuilder + .baseUrl(sessionParams.homeServerConnectionConfig.homeServerUri.toString()) + .build() + } } - @Provides + @Binds @SessionScope - @Named("SessionRealmConfiguration") - fun providesRealmConfiguration(sessionParams: SessionParams, context: Context): RealmConfiguration { - val childPath = sessionParams.credentials.userId.md5() - val directory = File(context.filesDir, childPath) + abstract fun bindSession(session: DefaultSession): Session - return RealmConfiguration.Builder() - .directory(directory) - .name("disk_store.realm") - .modules(SessionRealmModule()) - .deleteRealmIfMigrationNeeded() - .build() - } - - @Provides + @Binds + @IntoSet @SessionScope - fun providesMonarchy(@Named("SessionRealmConfiguration") - realmConfiguration: RealmConfiguration): Monarchy { - return Monarchy.Builder() - .setRealmConfiguration(realmConfiguration) - .build() - } + abstract fun bindGroupSummaryUpdater(groupSummaryUpdater: GroupSummaryUpdater): LiveEntityObserver - @Provides + @Binds + @IntoSet @SessionScope - fun providesRetrofit(sessionParams: SessionParams, retrofitBuilder: Retrofit.Builder): Retrofit { - return retrofitBuilder - .baseUrl(sessionParams.homeServerConnectionConfig.homeServerUri.toString()) - .build() - } + abstract fun bindEventsPruner(eventsPruner: EventsPruner): LiveEntityObserver - @Provides + @Binds + @IntoSet @SessionScope - fun providesFilterAPI(retrofit: Retrofit): FilterApi { - return retrofit.create(FilterApi::class.java) - } + abstract fun bindEventRelationsAggregationUpdater(groupSummaryUpdater: EventRelationsAggregationUpdater): LiveEntityObserver - @Provides + @Binds + @IntoSet @SessionScope - fun providesLiveEntityObservers(groupSummaryUpdater: GroupSummaryUpdater, - userEntityUpdater: UserEntityUpdater, - aggregationUpdater: EventRelationsAggregationUpdater, - eventsPruner: EventsPruner): List { - return listOf(groupSummaryUpdater, userEntityUpdater, aggregationUpdater, eventsPruner) - } + abstract fun bindUserEntityUpdater(groupSummaryUpdater: UserEntityUpdater): LiveEntityObserver } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/CacheModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/CacheModule.kt index 349dc246d1..e536e81b88 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/CacheModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/CacheModule.kt @@ -20,19 +20,28 @@ package im.vector.matrix.android.internal.session.cache import dagger.Binds import dagger.Module +import dagger.Provides import im.vector.matrix.android.api.session.cache.CacheService +import im.vector.matrix.android.internal.di.SessionDatabase import im.vector.matrix.android.internal.session.SessionScope +import io.realm.RealmConfiguration @Module internal abstract class CacheModule { + @Module + companion object { + @JvmStatic + @Provides + @SessionScope + @SessionDatabase + fun providesClearCacheTask(@SessionDatabase realmConfiguration: RealmConfiguration): ClearCacheTask { + return RealmClearCacheTask(realmConfiguration) + } + } + @Binds @SessionScope abstract fun bindCacheService(cacheService: DefaultCacheService): CacheService - @Binds - @SessionScope - abstract fun bindClearCacheTask(clearCacheTask: RealmClearCacheTask): ClearCacheTask - - } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/RealmClearCacheTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/ClearCacheTask.kt similarity index 88% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/RealmClearCacheTask.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/ClearCacheTask.kt index 67ed54dc29..bb756d3b0a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/RealmClearCacheTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/ClearCacheTask.kt @@ -22,11 +22,12 @@ import im.vector.matrix.android.internal.task.Task import io.realm.Realm import io.realm.RealmConfiguration import javax.inject.Inject +import javax.inject.Named internal interface ClearCacheTask : Task @SessionScope -internal class RealmClearCacheTask @Inject constructor(val realmConfiguration: RealmConfiguration) : ClearCacheTask { +internal class RealmClearCacheTask @Inject constructor(private val realmConfiguration: RealmConfiguration) : ClearCacheTask { override suspend fun execute(params: Unit): Try { return Try { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/DefaultCacheService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/DefaultCacheService.kt index 7dcb24e9c5..d38e7cb210 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/DefaultCacheService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/DefaultCacheService.kt @@ -18,13 +18,14 @@ package im.vector.matrix.android.internal.session.cache import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.session.cache.CacheService +import im.vector.matrix.android.internal.di.SessionDatabase import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith import javax.inject.Inject @SessionScope -internal class DefaultCacheService @Inject constructor(private val clearCacheTask: ClearCacheTask, +internal class DefaultCacheService @Inject constructor(@SessionDatabase private val clearCacheTask: ClearCacheTask, private val taskExecutor: TaskExecutor) : CacheService { override fun clearCache(callback: MatrixCallback) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt index ce5c8e586f..30c4b62937 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt @@ -34,7 +34,7 @@ import im.vector.matrix.android.api.session.room.model.message.MessageVideoConte import im.vector.matrix.android.internal.worker.DelegateWorkerFactory import im.vector.matrix.android.internal.network.ProgressRequestBody import im.vector.matrix.android.internal.session.room.send.SendEventWorker -import im.vector.matrix.android.internal.util.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.WorkerParamsFactory import timber.log.Timber import java.io.File diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterRepository.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterRepository.kt index 690db907be..f08c769fe4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterRepository.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterRepository.kt @@ -16,6 +16,7 @@ package im.vector.matrix.android.internal.session.filter +import im.vector.matrix.android.internal.di.SessionDatabase import im.vector.matrix.android.internal.database.model.FilterEntity import im.vector.matrix.android.internal.database.model.FilterEntityFields import im.vector.matrix.android.internal.database.query.getFilter @@ -26,7 +27,9 @@ import io.realm.kotlin.where import javax.inject.Inject @SessionScope -internal class DefaultFilterRepository @Inject constructor(val realmConfiguration: RealmConfiguration) : FilterRepository { +internal class DefaultFilterRepository @Inject constructor( + @SessionDatabase private val realmConfiguration: RealmConfiguration +) : FilterRepository { override fun storeFilter(filterBody: FilterBody, roomEventFilter: RoomEventFilter): Boolean { val result: Boolean diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GetGroupDataWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GetGroupDataWorker.kt index 4d35d0c712..1a07fd9336 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GetGroupDataWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GetGroupDataWorker.kt @@ -24,13 +24,16 @@ import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.squareup.moshi.JsonClass import im.vector.matrix.android.internal.worker.DelegateWorkerFactory -import im.vector.matrix.android.internal.util.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.WorkerParamsFactory internal class GetGroupDataWorker @AssistedInject constructor( @Assisted context: Context, - @Assisted workerParameters: WorkerParameters, + @Assisted params: WorkerParameters, private val getGroupDataTask: GetGroupDataTask -) : CoroutineWorker(context, workerParameters) { +) : CoroutineWorker(context, params) { + + @AssistedInject.Factory + interface Factory : DelegateWorkerFactory @JsonClass(generateAdapter = true) internal data class Params( @@ -52,7 +55,4 @@ internal class GetGroupDataWorker @AssistedInject constructor( return getGroupDataTask.execute(GetGroupDataTask.Params(groupId)) } - @AssistedInject.Factory - interface Factory : DelegateWorkerFactory - } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt index f1306b76af..81b56c08fd 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt @@ -26,7 +26,7 @@ import im.vector.matrix.android.internal.database.RealmLiveEntityObserver import im.vector.matrix.android.internal.database.model.GroupEntity import im.vector.matrix.android.internal.database.query.where import im.vector.matrix.android.internal.session.SessionScope -import im.vector.matrix.android.internal.util.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.WorkerParamsFactory import javax.inject.Inject private const val GET_GROUP_DATA_WORKER = "GET_GROUP_DATA_WORKER" diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomModule.kt index cc5e7aa8ab..48616570f0 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomModule.kt @@ -50,7 +50,9 @@ import im.vector.matrix.android.internal.session.room.read.DefaultSetReadMarkers import im.vector.matrix.android.internal.session.room.read.SetReadMarkersTask import im.vector.matrix.android.internal.session.room.relation.* import im.vector.matrix.android.internal.session.room.send.DefaultSendService +import im.vector.matrix.android.internal.session.room.state.DefaultSendStateTask import im.vector.matrix.android.internal.session.room.state.DefaultStateService +import im.vector.matrix.android.internal.session.room.state.SendStateTask import im.vector.matrix.android.internal.session.room.timeline.* import retrofit2.Retrofit @@ -135,6 +137,10 @@ internal abstract class RoomModule { @SessionScope abstract fun bindUpdateQuickReactionTask(updateQuickReactionTask: DefaultUpdateQuickReactionTask): UpdateQuickReactionTask + @Binds + @SessionScope + abstract fun bindSendStateTask(sendStateTask: DefaultSendStateTask): SendStateTask + @Binds @SessionScope abstract fun bindSendService(sendService: DefaultSendService): SendService diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/create/CreateRoomTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/create/CreateRoomTask.kt index a1f10c623f..50c102d37a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/create/CreateRoomTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/create/CreateRoomTask.kt @@ -20,6 +20,7 @@ import arrow.core.Try import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams import im.vector.matrix.android.api.session.room.model.create.CreateRoomResponse import im.vector.matrix.android.internal.database.RealmQueryLatch +import im.vector.matrix.android.internal.di.SessionDatabase import im.vector.matrix.android.internal.database.model.RoomEntity import im.vector.matrix.android.internal.database.model.RoomEntityFields import im.vector.matrix.android.internal.network.executeRequest @@ -33,7 +34,7 @@ internal interface CreateRoomTask : Task @SessionScope internal class DefaultCreateRoomTask @Inject constructor(private val roomAPI: RoomAPI, - private val realmConfiguration: RealmConfiguration) : CreateRoomTask { + @SessionDatabase private val realmConfiguration: RealmConfiguration) : CreateRoomTask { override suspend fun execute(params: CreateRoomParams): Try { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/EventsPruner.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/EventsPruner.kt index 4b663d5a26..a1bb65af97 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/EventsPruner.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/EventsPruner.kt @@ -44,8 +44,7 @@ internal class EventsPruner @Inject constructor(monarchy: Monarchy, override fun processChanges(inserted: List, updated: List, deleted: List) { Timber.v("Event pruner called with ${inserted.size} insertions") - val redactionEvents = inserted - .mapNotNull { it.asDomain() } + val redactionEvents = inserted.map { it.asDomain() } val params = PruneEventTask.Params( redactionEvents, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt index a48a0ad60b..7ae4e5dfd1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt @@ -31,7 +31,6 @@ import im.vector.matrix.android.internal.database.model.EventAnnotationsSummaryE import im.vector.matrix.android.internal.database.model.RoomEntity import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom import im.vector.matrix.android.internal.database.query.where -import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory import im.vector.matrix.android.internal.session.room.send.RedactEventWorker import im.vector.matrix.android.internal.session.room.send.SendEventWorker @@ -39,10 +38,9 @@ import im.vector.matrix.android.internal.session.room.timeline.TimelineSendEvent import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith import im.vector.matrix.android.internal.util.CancelableWork -import im.vector.matrix.android.internal.util.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.WorkerParamsFactory import im.vector.matrix.android.internal.util.tryTransactionAsync import timber.log.Timber -import javax.inject.Inject internal class DefaultRelationService constructor(private val roomId: String, private val eventFactory: LocalEchoEventFactory, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/SendRelationWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/SendRelationWorker.kt index de32c6f8b3..dbd9771421 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/SendRelationWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/SendRelationWorker.kt @@ -30,7 +30,7 @@ import im.vector.matrix.android.internal.worker.DelegateWorkerFactory import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.send.SendResponse -import im.vector.matrix.android.internal.util.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.WorkerParamsFactory internal class SendRelationWorker @AssistedInject constructor( @Assisted context: Context, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt index 62239a74b7..12fee96206 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt @@ -28,7 +28,7 @@ import im.vector.matrix.android.api.util.addTo import im.vector.matrix.android.internal.session.content.UploadContentWorker import im.vector.matrix.android.internal.session.room.timeline.TimelineSendEventWorkCommon import im.vector.matrix.android.internal.util.CancelableWork -import im.vector.matrix.android.internal.util.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.WorkerParamsFactory import timber.log.Timber import java.util.concurrent.TimeUnit diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EncryptEventWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EncryptEventWorker.kt index 70a9ddf05c..256f3d168b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EncryptEventWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EncryptEventWorker.kt @@ -28,7 +28,7 @@ import im.vector.matrix.android.api.session.crypto.CryptoService import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.room.send.SendState import im.vector.matrix.android.internal.crypto.model.MXEncryptEventContentResult -import im.vector.matrix.android.internal.util.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.WorkerParamsFactory import im.vector.matrix.android.internal.worker.DelegateWorkerFactory import java.util.concurrent.CountDownLatch @@ -49,7 +49,7 @@ internal class EncryptEventWorker @AssistedInject constructor( override fun doWork(): Result { val params = WorkerParamsFactory.fromData(inputData) - ?: return Result.success() + ?: return Result.success() val localEvent = params.event if (localEvent.eventId == null) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/RedactEventWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/RedactEventWorker.kt index 0054329f7f..7d45a2a6c9 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/RedactEventWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/RedactEventWorker.kt @@ -24,7 +24,7 @@ import com.squareup.moshi.JsonClass import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.room.RoomAPI -import im.vector.matrix.android.internal.util.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.WorkerParamsFactory import im.vector.matrix.android.internal.worker.DelegateWorkerFactory internal class RedactEventWorker @AssistedInject constructor( @@ -43,7 +43,7 @@ internal class RedactEventWorker @AssistedInject constructor( override fun doWork(): Result { val params = WorkerParamsFactory.fromData(inputData) - ?: return Result.failure() + ?: return Result.failure() val eventId = params.eventId val result = executeRequest { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt index 790db2cef3..6ff60da074 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt @@ -28,7 +28,7 @@ import im.vector.matrix.android.api.session.room.send.SendState import im.vector.matrix.android.internal.worker.DelegateWorkerFactory import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.room.RoomAPI -import im.vector.matrix.android.internal.util.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.WorkerParamsFactory internal class SendEventWorker @AssistedInject constructor( @Assisted context: Context, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/ReadReceiptHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/ReadReceiptHandler.kt index a7af1e3478..fafc75f0c8 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/ReadReceiptHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/ReadReceiptHandler.kt @@ -20,6 +20,7 @@ import im.vector.matrix.android.internal.database.model.ReadReceiptEntity import im.vector.matrix.android.internal.session.SessionScope import io.realm.Realm import timber.log.Timber +import javax.inject.Inject // the receipts dictionnaries @@ -30,7 +31,7 @@ import timber.log.Timber typealias ReadReceiptContent = Map>>> @SessionScope -internal class ReadReceiptHandler internal constructor() { +internal class ReadReceiptHandler @Inject constructor() { fun handle(realm: Realm, roomId: String, content: ReadReceiptContent?) { if (content == null) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTokenStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTokenStore.kt index d9a00636d1..17ca16805b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTokenStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTokenStore.kt @@ -16,6 +16,7 @@ package im.vector.matrix.android.internal.session.sync +import im.vector.matrix.android.internal.di.SessionDatabase import im.vector.matrix.android.internal.database.model.SyncEntity import im.vector.matrix.android.internal.session.SessionScope import io.realm.Realm @@ -23,7 +24,7 @@ import io.realm.RealmConfiguration import javax.inject.Inject @SessionScope -internal class SyncTokenStore @Inject constructor(private val realmConfiguration: RealmConfiguration) { +internal class SyncTokenStore @Inject constructor(@SessionDatabase private val realmConfiguration: RealmConfiguration) { fun getLastToken(): String? { val realm = Realm.getInstance(realmConfiguration) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt index 228e83baa9..944b62ee6c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt @@ -16,8 +16,10 @@ package im.vector.matrix.android.internal.task + import arrow.core.Try import im.vector.matrix.android.api.util.Cancelable +import im.vector.matrix.android.internal.di.MatrixScope import im.vector.matrix.android.internal.util.CancelableCoroutine import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import kotlinx.coroutines.GlobalScope @@ -26,10 +28,9 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import timber.log.Timber import javax.inject.Inject -import javax.inject.Singleton import kotlin.coroutines.EmptyCoroutineContext -@Singleton +@MatrixScope internal class TaskExecutor @Inject constructor(private val coroutineDispatchers: MatrixCoroutineDispatchers) { fun execute(task: ConfigurableTask): Cancelable { @@ -42,11 +43,11 @@ internal class TaskExecutor @Inject constructor(private val coroutineDispatchers } } resultOrFailure.fold({ - Timber.d(it, "Task failed") - task.callback.onFailure(it) - }, { - task.callback.onSuccess(it) - }) + Timber.d(it, "Task failed") + task.callback.onFailure(it) + }, { + task.callback.onSuccess(it) + }) } return CancelableCoroutine(job) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/BackgroundDetectionObserver.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/BackgroundDetectionObserver.kt index 5f85804f6c..a426bdd084 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/BackgroundDetectionObserver.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/BackgroundDetectionObserver.kt @@ -19,12 +19,15 @@ package im.vector.matrix.android.internal.util import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleObserver import androidx.lifecycle.OnLifecycleEvent +import im.vector.matrix.android.internal.di.MatrixScope import timber.log.Timber +import javax.inject.Inject /** * To be attached to ProcessLifecycleOwner lifecycle */ -internal class BackgroundDetectionObserver : LifecycleObserver { +@MatrixScope +internal class BackgroundDetectionObserver @Inject constructor() : LifecycleObserver { var isIsBackground: Boolean = false private set diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/StringProvider.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/StringProvider.kt index 14f2a825f5..479412cf45 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/StringProvider.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/StringProvider.kt @@ -19,11 +19,12 @@ package im.vector.matrix.android.internal.util import android.content.res.Resources import androidx.annotation.NonNull import androidx.annotation.StringRes +import dagger.Reusable import im.vector.matrix.android.internal.di.MatrixScope import javax.inject.Inject import javax.inject.Singleton -@MatrixScope +@Reusable internal class StringProvider @Inject constructor(private val resources: Resources) { /** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/DelegateWorkerFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/DelegateWorkerFactory.kt index cb0c7580b9..5141e06f10 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/DelegateWorkerFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/DelegateWorkerFactory.kt @@ -24,6 +24,6 @@ import androidx.work.WorkerParameters interface DelegateWorkerFactory { - fun create(appContext: Context, workerParameters: WorkerParameters): ListenableWorker + fun create(context: Context, params: WorkerParameters): ListenableWorker } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/MatrixWorkerFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/MatrixWorkerFactory.kt index 63d5836b5a..e31e300ef3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/MatrixWorkerFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/MatrixWorkerFactory.kt @@ -26,7 +26,6 @@ import im.vector.matrix.android.internal.di.MatrixScope import javax.inject.Inject import javax.inject.Provider -@MatrixScope class MatrixWorkerFactory @Inject constructor( private val workerFactories: Map, @JvmSuppressWildcards Provider> ) : WorkerFactory() { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/DI.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerBindingModule.kt similarity index 89% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/DI.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerBindingModule.kt index ec0d086679..20e75a8dd3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/DI.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerBindingModule.kt @@ -18,9 +18,7 @@ package im.vector.matrix.android.internal.worker -import androidx.work.ListenableWorker import dagger.Binds -import dagger.MapKey import dagger.Module import dagger.multibindings.IntoMap import im.vector.matrix.android.internal.session.content.UploadContentWorker @@ -29,12 +27,7 @@ import im.vector.matrix.android.internal.session.room.relation.SendRelationWorke import im.vector.matrix.android.internal.session.room.send.EncryptEventWorker import im.vector.matrix.android.internal.session.room.send.RedactEventWorker import im.vector.matrix.android.internal.session.room.send.SendEventWorker -import kotlin.reflect.KClass -@MapKey -@Target(AnnotationTarget.FUNCTION) -@Retention(AnnotationRetention.RUNTIME) -internal annotation class WorkerKey(val value: KClass) @Module internal interface WorkerBindingModule { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerKey.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerKey.kt new file mode 100644 index 0000000000..c5b0f45a12 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerKey.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.internal.worker + +import androidx.work.ListenableWorker +import dagger.MapKey +import kotlin.reflect.KClass + +@MapKey +@Target(AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class WorkerKey(val value: KClass) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/WorkerParamsFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerParamsFactory.kt similarity index 96% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/WorkerParamsFactory.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerParamsFactory.kt index 7c1cc72d17..87d17b9cea 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/WorkerParamsFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerParamsFactory.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package im.vector.matrix.android.internal.util +package im.vector.matrix.android.internal.worker import androidx.work.Data import im.vector.matrix.android.internal.di.MoshiProvider