From cf93e339155d590fc0e9e03420bc970c27f56e68 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 11 Dec 2024 17:33:16 +0000 Subject: [PATCH 1/2] Support new properties in posthog UTD reports Add a few new properties to the UTD reports we send to Posthog. --- .../android/libraries/matrix/impl/analytics/UtdTracker.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/analytics/UtdTracker.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/analytics/UtdTracker.kt index 56310a7b58..a8577bbe40 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/analytics/UtdTracker.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/analytics/UtdTracker.kt @@ -39,6 +39,10 @@ class UtdTracker( timeToDecryptMillis = info.timeToDecryptMs?.toInt() ?: -1, domain = Error.Domain.E2EE, name = name, + eventLocalAgeMillis = info.eventLocalAgeMillis.toInt(), + userTrustsOwnIdentity = info.userTrustsOwnIdentity, + isFederated = info.ownHomeserver != info.senderHomeserver, + isMatrixDotOrg = info.ownHomeserver == "matrix.org", ) analyticsService.capture(event) } From f29dd2961a992c502fa50d393558ba9917acf7a2 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 12 Dec 2024 11:30:59 +0000 Subject: [PATCH 2/2] Update UtdTracker tests --- .../matrix/impl/analytics/UtdTrackerTest.kt | 110 +++++++++++++++++- .../fixtures/factories/UnableToDecryptInfo.kt | 4 +- 2 files changed, 107 insertions(+), 7 deletions(-) diff --git a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/analytics/UtdTrackerTest.kt b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/analytics/UtdTrackerTest.kt index 62147d182c..deefe1a189 100644 --- a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/analytics/UtdTrackerTest.kt +++ b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/analytics/UtdTrackerTest.kt @@ -25,6 +25,7 @@ class UtdTrackerTest { eventId = AN_EVENT_ID.value, timeToDecryptMs = null, cause = UtdCause.UNKNOWN, + eventLocalAgeMillis = 100L, ) ) assertThat(fakeAnalyticsService.capturedEvents).containsExactly( @@ -34,7 +35,11 @@ class UtdTrackerTest { cryptoSDK = Error.CryptoSDK.Rust, timeToDecryptMillis = -1, domain = Error.Domain.E2EE, - name = Error.Name.OlmKeysNotSentError + name = Error.Name.OlmKeysNotSentError, + isFederated = false, + isMatrixDotOrg = false, + userTrustsOwnIdentity = false, + eventLocalAgeMillis = 100, ) ) assertThat(fakeAnalyticsService.screenEvents).isEmpty() @@ -59,7 +64,11 @@ class UtdTrackerTest { cryptoSDK = Error.CryptoSDK.Rust, timeToDecryptMillis = 123, domain = Error.Domain.E2EE, - name = Error.Name.OlmKeysNotSentError + name = Error.Name.OlmKeysNotSentError, + isFederated = false, + isMatrixDotOrg = false, + userTrustsOwnIdentity = false, + eventLocalAgeMillis = 0, ) ) assertThat(fakeAnalyticsService.screenEvents).isEmpty() @@ -84,7 +93,11 @@ class UtdTrackerTest { cryptoSDK = Error.CryptoSDK.Rust, timeToDecryptMillis = 123, domain = Error.Domain.E2EE, - name = Error.Name.ExpectedDueToMembership + name = Error.Name.ExpectedDueToMembership, + isFederated = false, + isMatrixDotOrg = false, + userTrustsOwnIdentity = false, + eventLocalAgeMillis = 0, ) ) assertThat(fakeAnalyticsService.screenEvents).isEmpty() @@ -109,7 +122,11 @@ class UtdTrackerTest { cryptoSDK = Error.CryptoSDK.Rust, timeToDecryptMillis = 123, domain = Error.Domain.E2EE, - name = Error.Name.ExpectedSentByInsecureDevice + name = Error.Name.ExpectedSentByInsecureDevice, + isFederated = false, + isMatrixDotOrg = false, + userTrustsOwnIdentity = false, + eventLocalAgeMillis = 0, ) ) } @@ -132,7 +149,90 @@ class UtdTrackerTest { cryptoSDK = Error.CryptoSDK.Rust, timeToDecryptMillis = 123, domain = Error.Domain.E2EE, - name = Error.Name.ExpectedVerificationViolation + name = Error.Name.ExpectedVerificationViolation, + isFederated = false, + isMatrixDotOrg = false, + userTrustsOwnIdentity = false, + eventLocalAgeMillis = 0, + ) + ) + } + + @Test + fun `when onUtd is called with different sender and receiver servers, the expected analytics Event is sent`() { + val fakeAnalyticsService = FakeAnalyticsService() + val sut = UtdTracker(fakeAnalyticsService) + sut.onUtd( + aRustUnableToDecryptInfo( + eventId = AN_EVENT_ID.value, + ownHomeserver = "example.com", + senderHomeserver = "matrix.org", + ) + ) + assertThat(fakeAnalyticsService.capturedEvents).containsExactly( + Error( + context = null, + cryptoModule = Error.CryptoModule.Rust, + cryptoSDK = Error.CryptoSDK.Rust, + timeToDecryptMillis = -1, + domain = Error.Domain.E2EE, + name = Error.Name.OlmKeysNotSentError, + isFederated = true, + isMatrixDotOrg = false, + userTrustsOwnIdentity = false, + eventLocalAgeMillis = 0, + ) + ) + } + + @Test + fun `when onUtd is called from a matrix-org user, the expected analytics Event is sent`() { + val fakeAnalyticsService = FakeAnalyticsService() + val sut = UtdTracker(fakeAnalyticsService) + sut.onUtd( + aRustUnableToDecryptInfo( + eventId = AN_EVENT_ID.value, + ownHomeserver = "matrix.org", + ) + ) + assertThat(fakeAnalyticsService.capturedEvents).containsExactly( + Error( + context = null, + cryptoModule = Error.CryptoModule.Rust, + cryptoSDK = Error.CryptoSDK.Rust, + timeToDecryptMillis = -1, + domain = Error.Domain.E2EE, + name = Error.Name.OlmKeysNotSentError, + isFederated = true, + isMatrixDotOrg = true, + userTrustsOwnIdentity = false, + eventLocalAgeMillis = 0, + ) + ) + } + + @Test + fun `when onUtd is called from a verified device, the expected analytics Event is sent`() { + val fakeAnalyticsService = FakeAnalyticsService() + val sut = UtdTracker(fakeAnalyticsService) + sut.onUtd( + aRustUnableToDecryptInfo( + eventId = AN_EVENT_ID.value, + userTrustsOwnIdentity = true, + ) + ) + assertThat(fakeAnalyticsService.capturedEvents).containsExactly( + Error( + context = null, + cryptoModule = Error.CryptoModule.Rust, + cryptoSDK = Error.CryptoSDK.Rust, + timeToDecryptMillis = -1, + domain = Error.Domain.E2EE, + name = Error.Name.OlmKeysNotSentError, + isFederated = false, + isMatrixDotOrg = false, + userTrustsOwnIdentity = true, + eventLocalAgeMillis = 0, ) ) } diff --git a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/factories/UnableToDecryptInfo.kt b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/factories/UnableToDecryptInfo.kt index 4743368472..775934716f 100644 --- a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/factories/UnableToDecryptInfo.kt +++ b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/factories/UnableToDecryptInfo.kt @@ -12,8 +12,8 @@ import uniffi.matrix_sdk_crypto.UtdCause internal fun aRustUnableToDecryptInfo( eventId: String, - timeToDecryptMs: ULong?, - cause: UtdCause, + timeToDecryptMs: ULong? = null, + cause: UtdCause = UtdCause.UNKNOWN, eventLocalAgeMillis: Long = 0L, userTrustsOwnIdentity: Boolean = false, senderHomeserver: String = "",