Re-enable SyncService.withEncryptionSync to improve decryption of notifications (#1199)

* Re-enable `SyncService.withEncryptionSync` to improve decryption of notifications.

* Add feature flag
This commit is contained in:
Jorge Martin Espinosa
2023-08-31 13:37:20 +02:00
committed by GitHub
parent 1c4eb45a60
commit e4124e93b8
8 changed files with 30 additions and 4 deletions

1
changelog.d/1198.bugfix Normal file
View File

@@ -0,0 +1 @@
Re-enable `SyncService.withEncryptionSync` to improve decryption of notifications.

View File

@@ -83,7 +83,8 @@ class DeveloperSettingsPresenter @Inject constructor(
features,
enabledFeatures,
event.feature,
event.isEnabled
event.isEnabled,
triggerClearCache = { handleEvents(DeveloperSettingsEvents.ClearCache) }
)
DeveloperSettingsEvents.ClearCache -> coroutineScope.clearCache(clearCacheAction)
}
@@ -122,12 +123,17 @@ class DeveloperSettingsPresenter @Inject constructor(
features: SnapshotStateMap<String, Feature>,
enabledFeatures: SnapshotStateMap<String, Boolean>,
featureUiModel: FeatureUiModel,
enabled: Boolean
enabled: Boolean,
triggerClearCache: () -> Unit,
) = launch {
val feature = features[featureUiModel.key] ?: return@launch
if (featureFlagService.setFeatureEnabled(feature, enabled)) {
enabledFeatures[featureUiModel.key] = enabled
}
if (featureUiModel.key == FeatureFlags.UseEncryptionSync.key) {
triggerClearCache()
}
}
private fun CoroutineScope.computeCacheSize(cacheSize: MutableState<Async<String>>) = launch {

View File

@@ -31,5 +31,11 @@ enum class FeatureFlags(
title = "Polls",
description = "Create poll and render poll events in the timeline",
defaultValue = false,
),
UseEncryptionSync(
key = "feature.useencryptionsync",
title = "Use encryption sync",
description = "Use the encryption sync API for decrypting notifications.",
defaultValue = true,
)
}

View File

@@ -31,6 +31,7 @@ class BuildtimeFeatureFlagProvider @Inject constructor() :
when (feature) {
FeatureFlags.LocationSharing -> true
FeatureFlags.Polls -> false
FeatureFlags.UseEncryptionSync -> true
}
} else {
false

View File

@@ -35,6 +35,7 @@ dependencies {
implementation(projects.libraries.androidutils)
implementation(projects.libraries.network)
implementation(projects.services.toolbox.api)
implementation(projects.libraries.featureflag.api)
api(projects.libraries.matrix.api)
implementation(libs.dagger)
implementation(projects.libraries.core)

View File

@@ -19,6 +19,8 @@ package io.element.android.libraries.matrix.impl
import android.content.Context
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.di.ApplicationContext
import io.element.android.libraries.featureflag.api.FeatureFlagService
import io.element.android.libraries.featureflag.api.FeatureFlags
import io.element.android.libraries.network.useragent.UserAgentProvider
import io.element.android.libraries.sessionstorage.api.SessionData
import io.element.android.libraries.sessionstorage.api.SessionStore
@@ -39,6 +41,7 @@ class RustMatrixClientFactory @Inject constructor(
private val sessionStore: SessionStore,
private val userAgentProvider: UserAgentProvider,
private val clock: SystemClock,
private val featureFlagsService: FeatureFlagService,
) {
suspend fun create(sessionData: SessionData): RustMatrixClient = withContext(coroutineDispatchers.io) {
@@ -53,7 +56,12 @@ class RustMatrixClientFactory @Inject constructor(
client.restoreSession(sessionData.toSession())
val syncService = client.syncService().finish()
val syncService = client.syncService().apply {
if (featureFlagsService.isFeatureEnabled(FeatureFlags.UseEncryptionSync)) {
withEncryptionSync(withCrossProcessLock = false, appIdentifier = null)
}
}
.finish()
RustMatrixClient(
client = client,

View File

@@ -63,6 +63,7 @@ dependencies {
implementation(projects.features.login.impl)
implementation(projects.features.networkmonitor.impl)
implementation(projects.services.toolbox.impl)
implementation(projects.libraries.featureflag.impl)
implementation(libs.coroutines.core)
coreLibraryDesugaring(libs.android.desugar)
}

View File

@@ -26,6 +26,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.core.view.WindowCompat
import io.element.android.libraries.featureflag.impl.DefaultFeatureFlagService
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
import io.element.android.libraries.matrix.impl.RustMatrixClientFactory
import io.element.android.libraries.matrix.impl.auth.RustMatrixAuthenticationService
@@ -54,7 +55,8 @@ class MainActivity : ComponentActivity() {
coroutineDispatchers = Singleton.coroutineDispatchers,
sessionStore = sessionStore,
userAgentProvider = userAgentProvider,
clock = DefaultSystemClock()
clock = DefaultSystemClock(),
featureFlagsService = DefaultFeatureFlagService(emptySet())
)
)
}