Skip to content

Commit

Permalink
Add dialog to prevent user
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle committed Feb 19, 2025
1 parent dd40f32 commit 4eee091
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 2 deletions.
3 changes: 3 additions & 0 deletions library/ui-strings/src/main/res/values-fr/strings_tchap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@

<!-- Logout Tchap -->
<string name="tchap_action_sign_out_confirmation">Pour des raisons de sécurité, la déconnexion supprimera toutes les clés de chiffrement de bout en bout, rendant l’historique des conversations chiffrées inaccessible lorsque vous vous reconnecterez. Cliquez sur exporter pour les sauvegarder avant de vous déconnecter.</string>
<string name="tchap_sign_out_rust_dialog_message">Pour des raisons de sécurité, merci de vous reconnecter à ${app_name}.\nLa version précédemment installée sur votre appareil ne permet pas de conserver votre coonexion.\nPour récupérer vos messages veuillez consulter notre aide.</string>
<string name="tchap_sign_out_login">Me reconnecter</string>
<string name="tchap_sign_out_help">Besoin d’aide ?</string>

<!-- Call -->
<string name="tchap_call_not_supported">${app_name} ne supporte pas les appels</string>
Expand Down
3 changes: 3 additions & 0 deletions library/ui-strings/src/main/res/values/strings_tchap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@

<!-- Logout Tchap -->
<string name="tchap_action_sign_out_confirmation">For security, logging out will delete any end-to-end encryption keys making previous encrypted chat history unreadable if you log back in.\nSelect export to backup them before signing out.</string>
<string name="tchap_sign_out_rust_dialog_message"><b>For security, please reconnect to ${app_name}.</b>\nDue to the previous version installed on your device you cannot keep signed in.\nTo retrieve your messages please see our help.</string>
<string name="tchap_sign_out_login">Reconnect</string>
<string name="tchap_sign_out_help">Need help ?</string>

<!-- Call -->
<string name="tchap_call_not_supported">${app_name} does not support calls</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.matrix.android.sdk.internal.crypto.store.db

import io.realm.DynamicRealm
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo020
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo021
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo024
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
import javax.inject.Inject
Expand All @@ -40,6 +42,8 @@ internal class RealmCryptoStoreMigration @Inject constructor() : MatrixRealmMigr
override fun hashCode() = 5000

override fun doMigrate(realm: DynamicRealm, oldVersion: Long) {
if (oldVersion < 20) MigrateCryptoTo020(realm).perform()
if (oldVersion < 21) MigrateCryptoTo021(realm).perform()
if (oldVersion < 24) MigrateCryptoTo024(realm).perform()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
*
* 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 org.matrix.android.sdk.internal.crypto.store.db.migration

import io.realm.DynamicRealm
import org.matrix.android.sdk.internal.crypto.store.db.model.MyDeviceLastSeenInfoEntityFields
import org.matrix.android.sdk.internal.util.database.RealmMigrator

/**
* This migration adds a new field into MyDeviceLastSeenInfoEntity corresponding to the last seen user agent.
*/
internal class MigrateCryptoTo020(realm: DynamicRealm) : RealmMigrator(realm, 20) {

override fun doMigrate(realm: DynamicRealm) {
realm.schema.get("MyDeviceLastSeenInfoEntity")
?.addField(MyDeviceLastSeenInfoEntityFields.LAST_SEEN_USER_AGENT, String::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2023 The Matrix.org Foundation C.I.C.
*
* 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 org.matrix.android.sdk.internal.crypto.store.db.migration

import io.realm.DynamicRealm
import org.matrix.android.sdk.api.crypto.MEGOLM_DEFAULT_ROTATION_MSGS
import org.matrix.android.sdk.api.crypto.MEGOLM_DEFAULT_ROTATION_PERIOD_MS
import org.matrix.android.sdk.internal.crypto.store.db.model.CryptoRoomEntityFields
import org.matrix.android.sdk.internal.util.database.RealmMigrator

/**
* This migration stores the rotation parameters for megolm oubound sessions.
*/
internal class MigrateCryptoTo021(realm: DynamicRealm) : RealmMigrator(realm, 21) {

override fun doMigrate(realm: DynamicRealm) {
realm.schema.get("CryptoRoomEntity")
?.addField(CryptoRoomEntityFields.ROTATION_PERIOD_MS, Long::class.java)
?.setNullable(CryptoRoomEntityFields.ROTATION_PERIOD_MS, true)
?.addField(CryptoRoomEntityFields.ROTATION_PERIOD_MSGS, Long::class.java)
?.setNullable(CryptoRoomEntityFields.ROTATION_PERIOD_MSGS, true)
?.transform {
// As a migration we set the default (will be on par with existing code)
// A clear cache will have the correct values.
it.setLong(CryptoRoomEntityFields.ROTATION_PERIOD_MS, MEGOLM_DEFAULT_ROTATION_PERIOD_MS)
it.setLong(CryptoRoomEntityFields.ROTATION_PERIOD_MSGS, MEGOLM_DEFAULT_ROTATION_MSGS)
}
}
}
31 changes: 29 additions & 2 deletions vector/src/main/java/im/vector/app/features/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import im.vector.app.core.extensions.startSyncing
import im.vector.app.core.extensions.vectorStore
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.core.utils.deleteAllFiles
import im.vector.app.core.utils.openUrlInChromeCustomTab
import im.vector.app.databinding.ActivityMainBinding
import im.vector.app.features.analytics.VectorAnalytics
import im.vector.app.features.analytics.plan.ViewRoom
Expand All @@ -39,6 +40,7 @@ import im.vector.app.features.pin.lockscreen.crypto.LockScreenKeyRepository
import im.vector.app.features.pin.lockscreen.pincode.PinCodeHelper
import im.vector.app.features.popup.PopupAlertManager
import im.vector.app.features.session.VectorSessionStore
import im.vector.app.features.settings.VectorSettingsUrls
import im.vector.app.features.signout.hard.SignedOutActivity
import im.vector.app.features.start.StartAppAction
import im.vector.app.features.start.StartAppAndroidService
Expand Down Expand Up @@ -82,6 +84,9 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
private const val EXTRA_INIT_SESSION = "EXTRA_INIT_SESSION"
private const val EXTRA_ROOM_ID = "EXTRA_ROOM_ID"
private const val ACTION_ROOM_DETAILS_FROM_SHORTCUT = "ROOM_DETAILS_FROM_SHORTCUT"
private const val TCHAP_FAQ_UTD_URL =
"${VectorSettingsUrls.HELP}/fr/article/dechiffrement-en-cours-mes-messages-restent-verrouilles-atnp15/" +
"#3-b-tous-ou-une-partie-de-mes-anciens-messages-sont-illisibles"

// Special action to clear cache and/or clear credentials
fun restartApp(activity: Activity, args: MainActivityArgs) {
Expand Down Expand Up @@ -177,7 +182,8 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity

private fun handleAppStarted() {
// On the first run with rust crypto this would be false
if (!vectorPreferences.isOnRustCrypto()) {
val isOnRustCrypto = vectorPreferences.isOnRustCrypto()
if (!isOnRustCrypto) {
if (activeSessionHolder.hasActiveSession()) {
vectorPreferences.setHadExistingLegacyData(activeSessionHolder.getActiveSession().isOpenable)
} else {
Expand Down Expand Up @@ -210,9 +216,11 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
clearNotifications()
}
// Handle some wanted cleanup
// TCHAP handle account expiration
// TCHAP handle account expiration and rust migration
if (args.clearCache || args.clearCredentials || args.isAccountExpired) {
doCleanUp()
} else if (!isOnRustCrypto && activeSessionHolder.hasActiveSession()) {
showSignoutDialog()
} else {
startSyncing()
startNextActivityAndFinish()
Expand Down Expand Up @@ -311,6 +319,25 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
}
}

private fun showSignoutDialog() {
MaterialAlertDialogBuilder(this)
.setTitle(CommonStrings.dialog_title_warning)
.setMessage(CommonStrings.tchap_sign_out_rust_dialog_message)
.setPositiveButton(CommonStrings.tchap_sign_out_login) { _, _ ->
Timber.e("## SIGN_OUT: rust issue. previous version was too old")
val session = activeSessionHolder.getActiveSession()
val onboardingStore = session.vectorStore(this)
signout(session, onboardingStore, ignoreServerError = true)
}
.setNeutralButton(CommonStrings.tchap_sign_out_help) { _, _ ->
vectorPreferences.setIsOnRustCrypto(false)
openUrlInChromeCustomTab(this, null, TCHAP_FAQ_UTD_URL)
finish()
}
.setCancelable(false)
.show()
}

override fun handleInvalidToken(globalError: GlobalError.InvalidToken) {
// No op here
Timber.w("Ignoring invalid token global error")
Expand Down

0 comments on commit 4eee091

Please sign in to comment.