mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Move getCryptoVersion from CryptoService to Matrix companion, it does not need a session to get the value.
This simplify a lot accessing this data.
This commit is contained in:
parent
28fa4ab784
commit
7e41d731f6
@ -147,5 +147,12 @@ class Matrix(context: Context, matrixConfiguration: MatrixConfiguration) {
|
||||
fun getSdkVersion(): String {
|
||||
return BuildConfig.SDK_VERSION + " (" + BuildConfig.GIT_SDK_REVISION + ")"
|
||||
}
|
||||
|
||||
fun getCryptoVersion(longFormat: Boolean): String {
|
||||
val version = org.matrix.rustcomponents.sdk.crypto.version()
|
||||
val gitHash = org.matrix.rustcomponents.sdk.crypto.versionInfo().gitSha
|
||||
val vodozemac = org.matrix.rustcomponents.sdk.crypto.vodozemacVersion()
|
||||
return if (longFormat) "Rust SDK $version ($gitHash), Vodozemac $vodozemac" else version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,8 +60,6 @@ interface CryptoService {
|
||||
|
||||
suspend fun deleteDevices(@Size(min = 1) deviceIds: List<String>, userInteractiveAuthInterceptor: UserInteractiveAuthInterceptor)
|
||||
|
||||
fun getCryptoVersion(longFormat: Boolean): String
|
||||
|
||||
fun isCryptoEnabled(): Boolean
|
||||
|
||||
fun isRoomBlacklistUnverifiedDevices(roomId: String?): Boolean
|
||||
|
@ -183,13 +183,6 @@ internal class RustCryptoService @Inject constructor(
|
||||
deleteDevices(listOf(deviceId), userInteractiveAuthInterceptor)
|
||||
}
|
||||
|
||||
override fun getCryptoVersion(longFormat: Boolean): String {
|
||||
val version = org.matrix.rustcomponents.sdk.crypto.version()
|
||||
val gitHash = org.matrix.rustcomponents.sdk.crypto.versionInfo().gitSha
|
||||
val vodozemac = org.matrix.rustcomponents.sdk.crypto.vodozemacVersion()
|
||||
return if (longFormat) "Rust SDK $version ($gitHash), Vodozemac $vodozemac" else version
|
||||
}
|
||||
|
||||
override suspend fun getMyCryptoDevice(): CryptoDeviceInfo = withContext(coroutineDispatchers.io) {
|
||||
olmMachine.ownDevice()
|
||||
}
|
||||
|
@ -135,6 +135,7 @@ class VectorApplication :
|
||||
SuperProperties(
|
||||
appPlatform = SuperProperties.AppPlatform.EA,
|
||||
cryptoSDK = SuperProperties.CryptoSDK.Rust,
|
||||
cryptoSDKVersion = Matrix.getCryptoVersion(longFormat = false)
|
||||
)
|
||||
)
|
||||
invitesAcceptor.initialize()
|
||||
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.app.features.analytics.impl
|
||||
|
||||
import im.vector.app.ActiveSessionDataSource
|
||||
import im.vector.app.features.analytics.plan.SuperProperties
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.map
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Gathers the super properties that are static to this platform or
|
||||
* that can be automatically resolved from the current session.
|
||||
*/
|
||||
class AutoSuperPropertiesFlowProvider @Inject constructor(
|
||||
activeSessionDataSource: ActiveSessionDataSource,
|
||||
) {
|
||||
|
||||
val superPropertiesFlow: Flow<SuperProperties> = activeSessionDataSource.stream()
|
||||
.map { session ->
|
||||
SuperProperties(
|
||||
appPlatform = SuperProperties.AppPlatform.EA,
|
||||
cryptoSDK = SuperProperties.CryptoSDK.Rust,
|
||||
cryptoSDKVersion = session.getOrNull()?.cryptoService()?.getCryptoVersion(false)
|
||||
)
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
}
|
@ -42,7 +42,6 @@ class DefaultVectorAnalytics @Inject constructor(
|
||||
private val analyticsConfig: AnalyticsConfig,
|
||||
private val analyticsStore: AnalyticsStore,
|
||||
private val lateInitUserPropertiesFactory: LateInitUserPropertiesFactory,
|
||||
private val autoSuperPropertiesFlowProvider: AutoSuperPropertiesFlowProvider,
|
||||
@NamedGlobalScope private val globalScope: CoroutineScope
|
||||
) : VectorAnalytics {
|
||||
|
||||
@ -70,7 +69,6 @@ class DefaultVectorAnalytics @Inject constructor(
|
||||
override fun init() {
|
||||
observeUserConsent()
|
||||
observeAnalyticsId()
|
||||
observeAutoSuperProperties()
|
||||
}
|
||||
|
||||
override fun getUserConsent(): Flow<Boolean> {
|
||||
@ -118,12 +116,6 @@ class DefaultVectorAnalytics @Inject constructor(
|
||||
.launchIn(globalScope)
|
||||
}
|
||||
|
||||
private fun observeAutoSuperProperties() {
|
||||
autoSuperPropertiesFlowProvider.superPropertiesFlow.onEach {
|
||||
updateSuperProperties(it)
|
||||
}.launchIn(globalScope)
|
||||
}
|
||||
|
||||
private suspend fun identifyPostHog() {
|
||||
val id = analyticsId ?: return
|
||||
if (!userConsent.orFalse()) return
|
||||
|
@ -265,7 +265,7 @@ class BugReporter @Inject constructor(
|
||||
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
||||
userId = session.myUserId
|
||||
deviceId = session.sessionParams.deviceId
|
||||
olmVersion = session.cryptoService().getCryptoVersion(true)
|
||||
olmVersion = Matrix.getCryptoVersion(true)
|
||||
}
|
||||
|
||||
if (!mIsCancelled) {
|
||||
|
@ -96,7 +96,7 @@ class VectorSettingsHelpAboutFragment :
|
||||
|
||||
// olm version
|
||||
findPreference<VectorPreference>(VectorPreferences.SETTINGS_CRYPTO_VERSION_PREFERENCE_KEY)!!
|
||||
.summary = session.cryptoService().getCryptoVersion(true)
|
||||
.summary = Matrix.getCryptoVersion(true)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -18,7 +18,6 @@ package im.vector.app.features.analytics.impl
|
||||
|
||||
import im.vector.app.features.analytics.plan.SuperProperties
|
||||
import im.vector.app.test.fakes.FakeAnalyticsStore
|
||||
import im.vector.app.test.fakes.FakeAutoSuperPropertiesFlowProvider
|
||||
import im.vector.app.test.fakes.FakeLateInitUserPropertiesFactory
|
||||
import im.vector.app.test.fakes.FakePostHog
|
||||
import im.vector.app.test.fakes.FakePostHogFactory
|
||||
@ -46,7 +45,6 @@ class DefaultVectorAnalyticsTest {
|
||||
private val fakeAnalyticsStore = FakeAnalyticsStore()
|
||||
private val fakeLateInitUserPropertiesFactory = FakeLateInitUserPropertiesFactory()
|
||||
private val fakeSentryAnalytics = FakeSentryAnalytics()
|
||||
private val fakeAutoSuperPropertiesFlowProvider = FakeAutoSuperPropertiesFlowProvider()
|
||||
|
||||
private val defaultVectorAnalytics = DefaultVectorAnalytics(
|
||||
postHogFactory = FakePostHogFactory(fakePostHog.instance).instance,
|
||||
@ -55,7 +53,6 @@ class DefaultVectorAnalyticsTest {
|
||||
globalScope = CoroutineScope(Dispatchers.Unconfined),
|
||||
analyticsConfig = anAnalyticsConfig(isEnabled = true),
|
||||
lateInitUserPropertiesFactory = fakeLateInitUserPropertiesFactory.instance,
|
||||
autoSuperPropertiesFlowProvider = fakeAutoSuperPropertiesFlowProvider.instance,
|
||||
)
|
||||
|
||||
@Before
|
||||
@ -289,40 +286,6 @@ class DefaultVectorAnalyticsTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Update super properties from flow`() = runTest {
|
||||
fakeAnalyticsStore.givenUserContent(consent = true)
|
||||
|
||||
fakeAutoSuperPropertiesFlowProvider.postSuperProperty(
|
||||
SuperProperties(
|
||||
cryptoSDKVersion = "0"
|
||||
)
|
||||
)
|
||||
|
||||
val fakeEvent = aVectorAnalyticsEvent("THE_NAME", null)
|
||||
defaultVectorAnalytics.capture(fakeEvent)
|
||||
|
||||
fakePostHog.verifyEventTracked(
|
||||
"THE_NAME",
|
||||
mapOf(
|
||||
"cryptoSDKVersion" to "0"
|
||||
)
|
||||
)
|
||||
|
||||
fakeAutoSuperPropertiesFlowProvider.postSuperProperty(SuperProperties(
|
||||
cryptoSDKVersion = "1"
|
||||
))
|
||||
|
||||
defaultVectorAnalytics.capture(fakeEvent)
|
||||
|
||||
fakePostHog.verifyEventTracked(
|
||||
"THE_NAME",
|
||||
mapOf(
|
||||
"cryptoSDKVersion" to "1"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun Map<String, Any?>?.clearNulls(): Map<String, Any>? {
|
||||
if (this == null) return null
|
||||
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.app.test.fakes
|
||||
|
||||
import im.vector.app.features.analytics.impl.AutoSuperPropertiesFlowProvider
|
||||
import im.vector.app.features.analytics.plan.SuperProperties
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
|
||||
class FakeAutoSuperPropertiesFlowProvider {
|
||||
|
||||
val flow = MutableSharedFlow<SuperProperties>()
|
||||
|
||||
val instance = mockk<AutoSuperPropertiesFlowProvider>().also {
|
||||
every { it.superPropertiesFlow } returns flow
|
||||
}
|
||||
|
||||
suspend fun postSuperProperty(properties: SuperProperties) {
|
||||
flow.emit(properties)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user