Enforce mandatory session verification only for new logins (#2811)
* Enforce mandatory session verification only for new logins - Creates `AppMigration` base interface as a way to isolate migration logic, app migrations must implement this interface. - Creates `AppMigration01` with the existing logs removal migration and `AppMigration02` with the logic to allow existing sessions to skip verification. - Add `DefaultSessionPreferencesStoreFactory.remove(sessionId)` to allow a ephemeral session store access to exist outside the `SessionScope` for this new migration. * Fix tests * Add more tests. This also includes creating several abstractions. * Review changes. - Make `orderedMigrations` a class property, `migrations` just a constructor parameter to avoid incorrect usages. - Create `lastMigration` property too, use it instead of `MIGRATION_VERSION`.
This commit is contained in:
parent
2007752513
commit
5c59f6c20f
30 changed files with 370 additions and 51 deletions
|
|
@ -17,6 +17,9 @@
|
|||
package io.element.android.libraries.preferences.impl.store
|
||||
|
||||
import android.content.Context
|
||||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.features.preferences.api.store.SessionPreferencesStore
|
||||
import io.element.android.features.preferences.api.store.SessionPreferencesStoreFactory
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.di.ApplicationContext
|
||||
import io.element.android.libraries.di.SingleIn
|
||||
|
|
@ -28,10 +31,11 @@ import java.util.concurrent.ConcurrentHashMap
|
|||
import javax.inject.Inject
|
||||
|
||||
@SingleIn(AppScope::class)
|
||||
@ContributesBinding(AppScope::class)
|
||||
class DefaultSessionPreferencesStoreFactory @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
sessionObserver: SessionObserver,
|
||||
) {
|
||||
) : SessionPreferencesStoreFactory {
|
||||
private val cache = ConcurrentHashMap<SessionId, DefaultSessionPreferencesStore>()
|
||||
|
||||
init {
|
||||
|
|
@ -44,7 +48,11 @@ class DefaultSessionPreferencesStoreFactory @Inject constructor(
|
|||
})
|
||||
}
|
||||
|
||||
fun get(sessionId: SessionId, sessionCoroutineScope: CoroutineScope): DefaultSessionPreferencesStore = cache.getOrPut(sessionId) {
|
||||
override fun get(sessionId: SessionId, sessionCoroutineScope: CoroutineScope): SessionPreferencesStore = cache.getOrPut(sessionId) {
|
||||
DefaultSessionPreferencesStore(context, sessionId, sessionCoroutineScope)
|
||||
}
|
||||
|
||||
override fun remove(sessionId: SessionId) {
|
||||
cache.remove(sessionId)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue