@@ -34,12 +34,6 @@ import androidx.preference.PreferenceCategory
34
34
import androidx.preference.SwitchPreference
35
35
import androidx.recyclerview.widget.RecyclerView
36
36
import com.google.android.material.textfield.TextInputEditText
37
- import org.matrix.android.sdk.api.MatrixCallback
38
- import org.matrix.android.sdk.internal.crypto.crosssigning.isVerified
39
- import org.matrix.android.sdk.internal.crypto.model.ImportRoomKeysResult
40
- import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo
41
- import org.matrix.android.sdk.internal.crypto.model.rest.DevicesListResponse
42
- import org.matrix.android.sdk.rx.SecretsSynchronisationInfo
43
37
import im.vector.app.R
44
38
import im.vector.app.core.di.ActiveSessionHolder
45
39
import im.vector.app.core.dialogs.ExportKeysDialog
@@ -50,6 +44,7 @@ import im.vector.app.core.intent.getFilenameFromUri
50
44
import im.vector.app.core.platform.SimpleTextWatcher
51
45
import im.vector.app.core.preference.VectorPreference
52
46
import im.vector.app.core.preference.VectorPreferenceCategory
47
+ import im.vector.app.core.utils.copyToClipboard
53
48
import im.vector.app.core.utils.openFileSelection
54
49
import im.vector.app.core.utils.toast
55
50
import im.vector.app.features.crypto.keys.KeysExporter
@@ -65,6 +60,13 @@ import im.vector.app.features.themes.ThemeUtils
65
60
import io.reactivex.android.schedulers.AndroidSchedulers
66
61
import io.reactivex.disposables.Disposable
67
62
import me.gujun.android.span.span
63
+ import org.matrix.android.sdk.api.MatrixCallback
64
+ import org.matrix.android.sdk.api.extensions.getFingerprintHumanReadable
65
+ import org.matrix.android.sdk.internal.crypto.crosssigning.isVerified
66
+ import org.matrix.android.sdk.internal.crypto.model.ImportRoomKeysResult
67
+ import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo
68
+ import org.matrix.android.sdk.internal.crypto.model.rest.DevicesListResponse
69
+ import org.matrix.android.sdk.rx.SecretsSynchronisationInfo
68
70
import org.matrix.android.sdk.rx.rx
69
71
import javax.inject.Inject
70
72
@@ -85,6 +87,18 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
85
87
findPreference<PreferenceCategory >(VectorPreferences .SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY )!!
86
88
}
87
89
90
+ private val cryptoInfoDeviceNamePreference by lazy {
91
+ findPreference<VectorPreference >(" SETTINGS_ENCRYPTION_INFORMATION_DEVICE_NAME_PREFERENCE_KEY" )!!
92
+ }
93
+
94
+ private val cryptoInfoDeviceIdPreference by lazy {
95
+ findPreference<VectorPreference >(" SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY" )!!
96
+ }
97
+
98
+ private val cryptoInfoDeviceKeyPreference by lazy {
99
+ findPreference<VectorPreference >(" SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY" )!!
100
+ }
101
+
88
102
private val mCrossSigningStatePreference by lazy {
89
103
findPreference<VectorPreference >(VectorPreferences .SETTINGS_ENCRYPTION_CROSS_SIGNING_PREFERENCE_KEY )!!
90
104
}
@@ -225,9 +239,6 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
225
239
}
226
240
227
241
override fun bindPref () {
228
- // Push target
229
- refreshPushersList()
230
-
231
242
// Refresh Key Management section
232
243
refreshKeysManagementSection()
233
244
@@ -488,58 +499,48 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
488
499
489
500
/* *
490
501
* Build the cryptography preference section.
491
- *
492
- * @param aMyDeviceInfo the device info
493
502
*/
494
503
private fun refreshCryptographyPreference (devices : List <DeviceInfo >) {
495
504
showDeviceListPref.isEnabled = devices.isNotEmpty()
496
505
showDeviceListPref.summary = resources.getQuantityString(R .plurals.settings_active_sessions_count, devices.size, devices.size)
497
- // val userId = session.myUserId
498
- // val deviceId = session.sessionParams.deviceId
499
-
500
- // device name
501
- // if (null != aMyDeviceInfo) {
502
- // cryptoInfoDeviceNamePreference.summary = aMyDeviceInfo.displayName
503
- //
504
- // cryptoInfoDeviceNamePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
505
- // // TODO device can be rename only from the device list screen for the moment
506
- // // displayDeviceRenameDialog(aMyDeviceInfo)
507
- // true
508
- // }
509
- //
510
- // cryptoInfoDeviceNamePreference.onPreferenceLongClickListener = object : VectorPreference.OnPreferenceLongClickListener {
511
- // override fun onPreferenceLongClick(preference: Preference): Boolean {
512
- // activity?.let { copyToClipboard(it, aMyDeviceInfo.displayName!!) }
513
- // return true
514
- // }
515
- // }
516
- // }
517
- //
518
- // // crypto section: device ID
519
- // if (!deviceId.isNullOrEmpty()) {
520
- // cryptoInfoDeviceIdPreference.summary = deviceId
521
- //
522
- // cryptoInfoDeviceIdPreference.setOnPreferenceClickListener {
523
- // activity?.let { copyToClipboard(it, deviceId) }
524
- // true
525
- // }
526
- // }
527
- //
528
- // // crypto section: device key (fingerprint)
529
- // if (!deviceId.isNullOrEmpty() && userId.isNotEmpty()) {
530
- // val deviceInfo = session.getDeviceInfo(userId, deviceId)
531
- //
532
- // if (null != deviceInfo && !deviceInfo.fingerprint().isNullOrEmpty()) {
533
- // cryptoInfoTextPreference.summary = deviceInfo.getFingerprintHumanReadable()
534
- //
535
- // cryptoInfoTextPreference.setOnPreferenceClickListener {
536
- // deviceInfo.fingerprint()?.let {
537
- // copyToClipboard(requireActivity(), it)
538
- // }
539
- // true
540
- // }
541
- // }
542
- // }
506
+
507
+ val userId = session.myUserId
508
+ val deviceId = session.sessionParams.deviceId
509
+
510
+ val aMyDeviceInfo = devices.find { it.deviceId == deviceId }
511
+
512
+ // crypto section: device name
513
+ if (aMyDeviceInfo != null ) {
514
+ cryptoInfoDeviceNamePreference.summary = aMyDeviceInfo.displayName
515
+
516
+ cryptoInfoDeviceNamePreference.onPreferenceClickListener = Preference .OnPreferenceClickListener {
517
+ copyToClipboard(requireActivity(), aMyDeviceInfo.displayName ? : " " )
518
+ true
519
+ }
520
+ }
521
+
522
+ // crypto section: device ID
523
+ if (! deviceId.isNullOrEmpty()) {
524
+ cryptoInfoDeviceIdPreference.summary = deviceId
525
+
526
+ cryptoInfoDeviceIdPreference.setOnPreferenceClickListener {
527
+ copyToClipboard(requireActivity(), deviceId)
528
+ true
529
+ }
530
+ }
531
+
532
+ // crypto section: device key (fingerprint)
533
+ val deviceInfo = session.cryptoService().getDeviceInfo(userId, deviceId)
534
+
535
+ val fingerprint = deviceInfo?.fingerprint()
536
+ if (fingerprint?.isNotEmpty() == true ) {
537
+ cryptoInfoDeviceKeyPreference.summary = deviceInfo.getFingerprintHumanReadable()
538
+
539
+ cryptoInfoDeviceKeyPreference.setOnPreferenceClickListener {
540
+ copyToClipboard(requireActivity(), fingerprint)
541
+ true
542
+ }
543
+ }
543
544
544
545
sendToUnverifiedDevicesPref.isChecked = session.cryptoService().getGlobalBlacklistUnverifiedDevices()
545
546
@@ -580,103 +581,8 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
580
581
})
581
582
}
582
583
583
- // ==============================================================================================================
584
- // pushers list management
585
- // ==============================================================================================================
586
-
587
- /* *
588
- * Refresh the pushers list
589
- */
590
- private fun refreshPushersList () {
591
- activity?.let { _ ->
592
- /* TODO
593
- val pushManager = Matrix.getInstance(activity).pushManager
594
- val pushersList = ArrayList(pushManager.mPushersList)
595
-
596
- if (pushersList.isEmpty()) {
597
- preferenceScreen.removePreference(mPushersSettingsCategory)
598
- preferenceScreen.removePreference(mPushersSettingsDivider)
599
- return
600
- }
601
-
602
- // check first if there is an update
603
- var isNewList = true
604
- if (pushersList.size == mDisplayedPushers.size) {
605
- isNewList = !mDisplayedPushers.containsAll(pushersList)
606
- }
607
-
608
- if (isNewList) {
609
- // remove the displayed one
610
- mPushersSettingsCategory.removeAll()
611
-
612
- // add new emails list
613
- mDisplayedPushers = pushersList
614
-
615
- var index = 0
616
-
617
- for (pushRule in mDisplayedPushers) {
618
- if (null != pushRule.lang) {
619
- val isThisDeviceTarget = TextUtils.equals(pushManager.currentRegistrationToken, pushRule.pushkey)
620
-
621
- val preference = VectorPreference(activity).apply {
622
- mTypeface = if (isThisDeviceTarget) Typeface.BOLD else Typeface.NORMAL
623
- }
624
- preference.title = pushRule.deviceDisplayName
625
- preference.summary = pushRule.appDisplayName
626
- preference.key = PUSHER_PREFERENCE_KEY_BASE + index
627
- index++
628
- mPushersSettingsCategory.addPreference(preference)
629
-
630
- // the user cannot remove the self device target
631
- if (!isThisDeviceTarget) {
632
- preference.onPreferenceLongClickListener = object : VectorPreference.OnPreferenceLongClickListener {
633
- override fun onPreferenceLongClick(preference: Preference): Boolean {
634
- AlertDialog.Builder(activity)
635
- .setTitle(R.string.dialog_title_confirmation)
636
- .setMessage(R.string.settings_delete_notification_targets_confirmation)
637
- .setPositiveButton(R.string.remove)
638
- { _, _ ->
639
- displayLoadingView()
640
- pushManager.unregister(session, pushRule, object : MatrixCallback<Unit> {
641
- override fun onSuccess(info: Void?) {
642
- refreshPushersList()
643
- onCommonDone(null)
644
- }
645
-
646
- override fun onNetworkError(e: Exception) {
647
- onCommonDone(e.localizedMessage)
648
- }
649
-
650
- override fun onMatrixError(e: MatrixError) {
651
- onCommonDone(e.localizedMessage)
652
- }
653
-
654
- override fun onUnexpectedError(e: Exception) {
655
- onCommonDone(e.localizedMessage)
656
- }
657
- })
658
- }
659
- .setNegativeButton(R.string.cancel, null)
660
- .show()
661
- return true
662
- }
663
- }
664
- }
665
- }
666
- }
667
- }
668
- */
669
- }
670
- }
671
-
672
584
companion object {
673
585
private const val REQUEST_E2E_FILE_REQUEST_CODE = 123
674
586
private const val REQUEST_CODE_SAVE_MEGOLM_EXPORT = 124
675
-
676
- private const val PUSHER_PREFERENCE_KEY_BASE = " PUSHER_PREFERENCE_KEY_BASE"
677
- private const val DEVICES_PREFERENCE_KEY_BASE = " DEVICES_PREFERENCE_KEY_BASE"
678
-
679
- // TODO i18n
680
- const val LABEL_UNAVAILABLE_DATA = " none"
681
587
}
682
588
}
0 commit comments