From de5623e0f1932bac3e129c4f72a6e4ede1e8b305 Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 6 May 2024 12:39:56 +0200 Subject: [PATCH 1/3] Add a new crypto session state event --- .../analytics/plan/CryptoSessionState.kt | 83 +++++++++++++++++++ schemas/CryptoSessionState.json | 28 +++++++ types/swift/CryptoSessionState.swift | 62 ++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionState.kt create mode 100644 schemas/CryptoSessionState.json create mode 100644 types/swift/CryptoSessionState.swift diff --git a/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionState.kt b/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionState.kt new file mode 100644 index 0000000..7b7c592 --- /dev/null +++ b/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionState.kt @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021 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.plan + +import im.vector.app.features.analytics.itf.VectorAnalyticsEvent + +// GENERATED FILE, DO NOT EDIT. FOR MORE INFORMATION VISIT +// https://github.com/matrix-org/matrix-analytics-events/ + +/** + * Describe the current session crypto state, that is if the session is verified + * or not, if recovery is correctly setup. + */ +data class CryptoSessionState( + val recoveryState: RecoveryState, + val verificationState: VerificationState, +) : VectorAnalyticsEvent { + + enum class VerificationState { + /** + * The device is unverified. + */ + NotVerified, + + /** + * The state is unknown for now. + */ + Unknown, + + /** + * The device is considered to be verified, it has been signed by its + * user identity. + */ + Verified, + } + + enum class RecoveryState { + + /** + * No default secret storage key exists or it is disabled explicitly + * using the account data event. + */ + Disabled, + + /** + * Secret storage is set up and we have all the secrets locally. + */ + Enabled, + + /** + * Secret storage is set up but we're missing some secrets. + */ + Incomplete, + + /** + * The state is unknown for now. + */ + Unknown, + } + + override fun getName() = "CryptoSessionState" + + override fun getProperties(): Map? { + return mutableMapOf().apply { + put("recoveryState", recoveryState.name) + put("verificationState", verificationState.name) + }.takeIf { it.isNotEmpty() } + } +} diff --git a/schemas/CryptoSessionState.json b/schemas/CryptoSessionState.json new file mode 100644 index 0000000..e094d81 --- /dev/null +++ b/schemas/CryptoSessionState.json @@ -0,0 +1,28 @@ +{ + "type": "object", + "description": "Describe the current session crypto state, that is if the session is verified or not, if recovery is correctly setup.", + "properties": { + "eventName": { + "enum": ["CryptoSessionState"] + }, + "verificationState": { + "type": "string", + "oneOf": [ + {"const": "Unknown", "description": "The state is unknown for now."}, + {"const": "Verified", "description": "The device is considered to be verified, it has been signed by its user identity."}, + {"const": "NotVerified", "description": "The device is unverified."} + ] + }, + "recoveryState": { + "type": "string", + "oneOf": [ + {"const": "Unknown", "description": "The state is unknown for now."}, + {"const": "Enabled", "description": "Secret storage is set up and we have all the secrets locally."}, + {"const": "Disabled", "description": "No default secret storage key exists or it is disabled explicitly using the account data event."}, + {"const": "Incomplete", "description": "Secret storage is set up but we're missing some secrets."} + ] + } + }, + "required": ["eventName","verificationState", "recoveryState"], + "additionalProperties": false +} diff --git a/types/swift/CryptoSessionState.swift b/types/swift/CryptoSessionState.swift new file mode 100644 index 0000000..030654e --- /dev/null +++ b/types/swift/CryptoSessionState.swift @@ -0,0 +1,62 @@ +// +// Copyright 2021 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. +// + +import Foundation + +// GENERATED FILE, DO NOT EDIT. FOR MORE INFORMATION VISIT +// https://github.com/matrix-org/matrix-analytics-events/ + +/// Describe the current session crypto state, that is if the session is verified or not, if recovery is correctly setup. +extension AnalyticsEvent { + public struct CryptoSessionState: AnalyticsEventProtocol { + public let eventName = "CryptoSessionState" + + public let recoveryState: RecoveryState + public let verificationState: VerificationState + + public init(recoveryState: RecoveryState, verificationState: VerificationState) { + self.recoveryState = recoveryState + self.verificationState = verificationState + } + + public enum VerificationState: String { + /// The device is unverified. + case NotVerified + /// The state is unknown for now. + case Unknown + /// The device is considered to be verified, it has been signed by its user identity. + case Verified + } + + public enum RecoveryState: String { + /// No default secret storage key exists or it is disabled explicitly using the account data event. + case Disabled + /// Secret storage is set up and we have all the secrets locally. + case Enabled + /// Secret storage is set up but we're missing some secrets. + case Incomplete + /// The state is unknown for now. + case Unknown + } + + public var properties: [String: Any] { + return [ + "recoveryState": recoveryState.rawValue, + "verificationState": verificationState.rawValue + ] + } + } +} From 0c24da06a14a883d31b58b4f6982c4c2e74d9c96 Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 6 May 2024 15:54:34 +0200 Subject: [PATCH 2/3] Add user property --- .../analytics/plan/CryptoSessionState.kt | 10 ----- .../features/analytics/plan/UserProperties.kt | 37 +++++++++++++++++++ schemas/CryptoSessionState.json | 2 - schemas/UserProperties.json | 15 ++++++++ types/swift/CryptoSessionState.swift | 4 -- types/swift/UserProperties.swift | 26 ++++++++++++- 6 files changed, 76 insertions(+), 18 deletions(-) diff --git a/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionState.kt b/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionState.kt index 7b7c592..aa07faa 100644 --- a/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionState.kt +++ b/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionState.kt @@ -36,11 +36,6 @@ data class CryptoSessionState( */ NotVerified, - /** - * The state is unknown for now. - */ - Unknown, - /** * The device is considered to be verified, it has been signed by its * user identity. @@ -65,11 +60,6 @@ data class CryptoSessionState( * Secret storage is set up but we're missing some secrets. */ Incomplete, - - /** - * The state is unknown for now. - */ - Unknown, } override fun getName() = "CryptoSessionState" diff --git a/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/UserProperties.kt b/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/UserProperties.kt index 0172045..67368f9 100644 --- a/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/UserProperties.kt +++ b/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/UserProperties.kt @@ -40,6 +40,8 @@ data class UserProperties( * Number of spaces (and sub-spaces) the user is joined to. */ val numSpaces: Int? = null, + val recoveryState: RecoveryState? = null, + val verificationState: VerificationState? = null, ) { enum class FtueUseCaseSelection { @@ -87,12 +89,47 @@ data class UserProperties( Unreads, } + enum class VerificationState { + + /** + * The device is unverified. + */ + NotVerified, + + /** + * The device is considered to be verified, it has been signed by its + * user identity. + */ + Verified, + } + + enum class RecoveryState { + + /** + * No default secret storage key exists or it is disabled explicitly + * using the account data event. + */ + Disabled, + + /** + * Secret storage is set up and we have all the secrets locally. + */ + Enabled, + + /** + * Secret storage is set up but we're missing some secrets. + */ + Incomplete, + } + fun getProperties(): Map? { return mutableMapOf().apply { allChatsActiveFilter?.let { put("allChatsActiveFilter", it.name) } ftueUseCaseSelection?.let { put("ftueUseCaseSelection", it.name) } numFavouriteRooms?.let { put("numFavouriteRooms", it) } numSpaces?.let { put("numSpaces", it) } + recoveryState?.let { put("recoveryState", it.name) } + verificationState?.let { put("verificationState", it.name) } }.takeIf { it.isNotEmpty() } } } diff --git a/schemas/CryptoSessionState.json b/schemas/CryptoSessionState.json index e094d81..b82ecfc 100644 --- a/schemas/CryptoSessionState.json +++ b/schemas/CryptoSessionState.json @@ -8,7 +8,6 @@ "verificationState": { "type": "string", "oneOf": [ - {"const": "Unknown", "description": "The state is unknown for now."}, {"const": "Verified", "description": "The device is considered to be verified, it has been signed by its user identity."}, {"const": "NotVerified", "description": "The device is unverified."} ] @@ -16,7 +15,6 @@ "recoveryState": { "type": "string", "oneOf": [ - {"const": "Unknown", "description": "The state is unknown for now."}, {"const": "Enabled", "description": "Secret storage is set up and we have all the secrets locally."}, {"const": "Disabled", "description": "No default secret storage key exists or it is disabled explicitly using the account data event."}, {"const": "Incomplete", "description": "Secret storage is set up but we're missing some secrets."} diff --git a/schemas/UserProperties.json b/schemas/UserProperties.json index d8dede5..2bb28e6 100644 --- a/schemas/UserProperties.json +++ b/schemas/UserProperties.json @@ -59,6 +59,21 @@ {"const": "Group", "description": "Modern layout."}, {"const": "Compact", "description": "Modern layout with compact option enabled."} ] + }, + "verificationState": { + "type": "string", + "oneOf": [ + {"const": "Verified", "description": "The device is considered to be verified, it has been signed by its user identity."}, + {"const": "NotVerified", "description": "The device is unverified."} + ] + }, + "recoveryState": { + "type": "string", + "oneOf": [ + {"const": "Enabled", "description": "Secret storage is set up and we have all the secrets locally."}, + {"const": "Disabled", "description": "No default secret storage key exists or it is disabled explicitly using the account data event."}, + {"const": "Incomplete", "description": "Secret storage is set up but we're missing some secrets."} + ] } }, "required": [], diff --git a/types/swift/CryptoSessionState.swift b/types/swift/CryptoSessionState.swift index 030654e..87600ba 100644 --- a/types/swift/CryptoSessionState.swift +++ b/types/swift/CryptoSessionState.swift @@ -35,8 +35,6 @@ extension AnalyticsEvent { public enum VerificationState: String { /// The device is unverified. case NotVerified - /// The state is unknown for now. - case Unknown /// The device is considered to be verified, it has been signed by its user identity. case Verified } @@ -48,8 +46,6 @@ extension AnalyticsEvent { case Enabled /// Secret storage is set up but we're missing some secrets. case Incomplete - /// The state is unknown for now. - case Unknown } public var properties: [String: Any] { diff --git a/types/swift/UserProperties.swift b/types/swift/UserProperties.swift index d4b6d54..3b1060a 100644 --- a/types/swift/UserProperties.swift +++ b/types/swift/UserProperties.swift @@ -31,12 +31,16 @@ extension AnalyticsEvent { public let numFavouriteRooms: Int? /// Number of spaces (and sub-spaces) the user is joined to. public let numSpaces: Int? + public let recoveryState: RecoveryState? + public let verificationState: VerificationState? - public init(allChatsActiveFilter: AllChatsActiveFilter?, ftueUseCaseSelection: FtueUseCaseSelection?, numFavouriteRooms: Int?, numSpaces: Int?) { + public init(allChatsActiveFilter: AllChatsActiveFilter?, ftueUseCaseSelection: FtueUseCaseSelection?, numFavouriteRooms: Int?, numSpaces: Int?, recoveryState: RecoveryState?, verificationState: VerificationState?) { self.allChatsActiveFilter = allChatsActiveFilter self.ftueUseCaseSelection = ftueUseCaseSelection self.numFavouriteRooms = numFavouriteRooms self.numSpaces = numSpaces + self.recoveryState = recoveryState + self.verificationState = verificationState } public enum FtueUseCaseSelection: String { @@ -61,12 +65,30 @@ extension AnalyticsEvent { case Unreads } + public enum VerificationState: String { + /// The device is unverified. + case NotVerified + /// The device is considered to be verified, it has been signed by its user identity. + case Verified + } + + public enum RecoveryState: String { + /// No default secret storage key exists or it is disabled explicitly using the account data event. + case Disabled + /// Secret storage is set up and we have all the secrets locally. + case Enabled + /// Secret storage is set up but we're missing some secrets. + case Incomplete + } + public var properties: [String: Any?] { return [ "allChatsActiveFilter": allChatsActiveFilter?.rawValue, "ftueUseCaseSelection": ftueUseCaseSelection?.rawValue, "numFavouriteRooms": numFavouriteRooms, - "numSpaces": numSpaces + "numSpaces": numSpaces, + "recoveryState": recoveryState?.rawValue, + "verificationState": verificationState?.rawValue ] } } From 6c0c51765bf938e450a884ea3787c3f0549717ad Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 6 May 2024 16:20:46 +0200 Subject: [PATCH 3/3] Better comments --- ...{CryptoSessionState.kt => CryptoSessionStateChange.kt} | 2 +- .../vector/app/features/analytics/plan/UserProperties.kt | 8 ++++++++ ...ptoSessionState.json => CryptoSessionStateChange.json} | 0 schemas/UserProperties.json | 2 ++ ...oSessionState.swift => CryptoSessionStateChange.swift} | 2 +- types/swift/UserProperties.swift | 2 ++ 6 files changed, 14 insertions(+), 2 deletions(-) rename kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/{CryptoSessionState.kt => CryptoSessionStateChange.kt} (98%) rename schemas/{CryptoSessionState.json => CryptoSessionStateChange.json} (100%) rename types/swift/{CryptoSessionState.swift => CryptoSessionStateChange.swift} (96%) diff --git a/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionState.kt b/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionStateChange.kt similarity index 98% rename from kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionState.kt rename to kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionStateChange.kt index aa07faa..3554882 100644 --- a/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionState.kt +++ b/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/CryptoSessionStateChange.kt @@ -25,7 +25,7 @@ import im.vector.app.features.analytics.itf.VectorAnalyticsEvent * Describe the current session crypto state, that is if the session is verified * or not, if recovery is correctly setup. */ -data class CryptoSessionState( +data class CryptoSessionStateChange( val recoveryState: RecoveryState, val verificationState: VerificationState, ) : VectorAnalyticsEvent { diff --git a/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/UserProperties.kt b/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/UserProperties.kt index 67368f9..4bcbae7 100644 --- a/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/UserProperties.kt +++ b/kotlin/lib/src/main/java/im/vector/app/features/analytics/plan/UserProperties.kt @@ -40,7 +40,15 @@ data class UserProperties( * Number of spaces (and sub-spaces) the user is joined to. */ val numSpaces: Int? = null, + /** + * Describe the current session recovery state, that if 4S is setup, + * complete (all secrets cached) or not. + */ val recoveryState: RecoveryState? = null, + /** + * Describe the current session verification state, that is if the + * session is verified or not. + */ val verificationState: VerificationState? = null, ) { diff --git a/schemas/CryptoSessionState.json b/schemas/CryptoSessionStateChange.json similarity index 100% rename from schemas/CryptoSessionState.json rename to schemas/CryptoSessionStateChange.json diff --git a/schemas/UserProperties.json b/schemas/UserProperties.json index 2bb28e6..9c3738e 100644 --- a/schemas/UserProperties.json +++ b/schemas/UserProperties.json @@ -61,6 +61,7 @@ ] }, "verificationState": { + "description": "Describe the current session verification state, that is if the session is verified or not.", "type": "string", "oneOf": [ {"const": "Verified", "description": "The device is considered to be verified, it has been signed by its user identity."}, @@ -68,6 +69,7 @@ ] }, "recoveryState": { + "description": "Describe the current session recovery state, that if 4S is setup, complete (all secrets cached) or not.", "type": "string", "oneOf": [ {"const": "Enabled", "description": "Secret storage is set up and we have all the secrets locally."}, diff --git a/types/swift/CryptoSessionState.swift b/types/swift/CryptoSessionStateChange.swift similarity index 96% rename from types/swift/CryptoSessionState.swift rename to types/swift/CryptoSessionStateChange.swift index 87600ba..2609a3f 100644 --- a/types/swift/CryptoSessionState.swift +++ b/types/swift/CryptoSessionStateChange.swift @@ -21,7 +21,7 @@ import Foundation /// Describe the current session crypto state, that is if the session is verified or not, if recovery is correctly setup. extension AnalyticsEvent { - public struct CryptoSessionState: AnalyticsEventProtocol { + public struct CryptoSessionStateChange: AnalyticsEventProtocol { public let eventName = "CryptoSessionState" public let recoveryState: RecoveryState diff --git a/types/swift/UserProperties.swift b/types/swift/UserProperties.swift index 3b1060a..ae67dd9 100644 --- a/types/swift/UserProperties.swift +++ b/types/swift/UserProperties.swift @@ -31,7 +31,9 @@ extension AnalyticsEvent { public let numFavouriteRooms: Int? /// Number of spaces (and sub-spaces) the user is joined to. public let numSpaces: Int? + /// Describe the current session recovery state, that if 4S is setup, complete (all secrets cached) or not. public let recoveryState: RecoveryState? + /// Describe the current session verification state, that is if the session is verified or not. public let verificationState: VerificationState? public init(allChatsActiveFilter: AllChatsActiveFilter?, ftueUseCaseSelection: FtueUseCaseSelection?, numFavouriteRooms: Int?, numSpaces: Int?, recoveryState: RecoveryState?, verificationState: VerificationState?) {