Dagger: make SDK DI working

This commit is contained in:
ganfra 2019-06-17 18:17:37 +02:00
parent 4be0ab87fc
commit c2c2d0b21e
42 changed files with 544 additions and 216 deletions

View File

@ -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

View File

@ -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<String, SessionComponent>()
private val sessions = HashMap<String, Session>()

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()
}
}



View File

@ -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

}

View File

@ -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)
}

}

View File

@ -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<SessionParams> {
return Try {

View File

@ -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

View File

@ -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




}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()
}

}

View File

@ -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()

View File

@ -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<LiveEntityObserver>,
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()

View File

@ -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(

View File

@ -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<LiveEntityObserver> {
return listOf<LiveEntityObserver>(groupSummaryUpdater, userEntityUpdater, aggregationUpdater, eventsPruner)
}
abstract fun bindUserEntityUpdater(groupSummaryUpdater: UserEntityUpdater): LiveEntityObserver

}

View File

@ -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


}

View File

@ -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<Unit, Unit>

@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<Unit> {
return Try {

View File

@ -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<Unit>) {

View File

@ -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


View File

@ -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

View File

@ -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

}

View File

@ -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"

View File

@ -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

View File

@ -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<CreateRoomParams, String>

@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<String> {

View File

@ -44,8 +44,7 @@ internal class EventsPruner @Inject constructor(monarchy: Monarchy,

override fun processChanges(inserted: List<EventEntity>, updated: List<EventEntity>, deleted: List<EventEntity>) {
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,

View File

@ -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,

View File

@ -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,

View File

@ -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


View File

@ -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<Params>(inputData)
?: return Result.success()
?: return Result.success()

val localEvent = params.event
if (localEvent.eventId == null) {

View File

@ -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<Params>(inputData)
?: return Result.failure()
?: return Result.failure()

val eventId = params.eventId
val result = executeRequest<SendResponse> {

View File

@ -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,

View File

@ -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<String, Map<String, Map<String, Map<String, Double>>>>

@SessionScope
internal class ReadReceiptHandler internal constructor() {
internal class ReadReceiptHandler @Inject constructor() {

fun handle(realm: Realm, roomId: String, content: ReadReceiptContent?) {
if (content == null) {

View File

@ -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)

View File

@ -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 <PARAMS, RESULT> execute(task: ConfigurableTask<PARAMS, RESULT>): 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)
}

View File

@ -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

View File

@ -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) {

/**

View File

@ -24,6 +24,6 @@ import androidx.work.WorkerParameters

interface DelegateWorkerFactory {

fun create(appContext: Context, workerParameters: WorkerParameters): ListenableWorker
fun create(context: Context, params: WorkerParameters): ListenableWorker

}

View File

@ -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<Class<out ListenableWorker>, @JvmSuppressWildcards Provider<DelegateWorkerFactory>>
) : WorkerFactory() {

View File

@ -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<out ListenableWorker>)

@Module
internal interface WorkerBindingModule {

View File

@ -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<out ListenableWorker>)

View File

@ -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