From ae15c4dd9fc3e7e4c1a499386c5e79014d5dc4b9 Mon Sep 17 00:00:00 2001 From: Anton Chekulaev Date: Fri, 13 Nov 2020 02:05:26 +1100 Subject: [PATCH] Backup enabled preference flag reset. General backup restore cleanup. --- build.gradle | 4 ++-- .../loki/activities/BackupRestoreActivity.kt | 23 +++++++++---------- .../securesms/loki/utilities/ViewUtilities.kt | 2 -- .../securesms/util/TextSecurePreferences.java | 16 ++++++------- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index 92cf1f0594..27bffc7a19 100644 --- a/build.gradle +++ b/build.gradle @@ -90,6 +90,8 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0' + implementation 'androidx.activity:activity-ktx:1.1.0' + implementation 'androidx.fragment:fragment-ktx:1.3.0-beta01' implementation ("com.google.firebase:firebase-messaging:18.0.0") { exclude group: 'com.google.firebase', module: 'firebase-core' @@ -159,8 +161,6 @@ dependencies { implementation "com.squareup.okhttp3:okhttp:3.12.1" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9' - implementation 'androidx.fragment:fragment-ktx:1.3.0-beta01' - implementation 'androidx.activity:activity-ktx:1.1.0' implementation "nl.komponents.kovenant:kovenant:$kovenant_version" implementation "nl.komponents.kovenant:kovenant-android:$kovenant_version" implementation "com.github.lelloman:android-identicons:v11" diff --git a/src/org/thoughtcrime/securesms/loki/activities/BackupRestoreActivity.kt b/src/org/thoughtcrime/securesms/loki/activities/BackupRestoreActivity.kt index 344cebbd3b..5544941436 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/BackupRestoreActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/BackupRestoreActivity.kt @@ -36,8 +36,6 @@ import org.thoughtcrime.securesms.backup.FullBackupImporter.DatabaseDowngradeExc import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.logging.Log -import org.thoughtcrime.securesms.loki.utilities.fadeIn -import org.thoughtcrime.securesms.loki.utilities.fadeOut import org.thoughtcrime.securesms.loki.utilities.setUpActionBarSessionLogo import org.thoughtcrime.securesms.loki.utilities.show import org.thoughtcrime.securesms.notifications.NotificationChannels @@ -92,14 +90,14 @@ class BackupRestoreActivity : BaseActionBarActivity() { // React to backup import result. viewModel.backupImportResult.observe(this) { result -> if (result != null) when (result) { - BackupRestoreViewModel.BackupImportResult.SUCCESS -> { + BackupRestoreViewModel.BackupRestoreResult.SUCCESS -> { val intent = Intent(this, HomeActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK this.show(intent) } - BackupRestoreViewModel.BackupImportResult.FAILURE_VERSION_DOWNGRADE -> + BackupRestoreViewModel.BackupRestoreResult.FAILURE_VERSION_DOWNGRADE -> Toast.makeText(this, R.string.RegistrationActivity_backup_failure_downgrade, Toast.LENGTH_LONG).show() - BackupRestoreViewModel.BackupImportResult.FAILURE_UNKNOWN -> + BackupRestoreViewModel.BackupRestoreResult.FAILURE_UNKNOWN -> Toast.makeText(this, R.string.RegistrationActivity_incorrect_backup_passphrase, Toast.LENGTH_LONG).show() } } @@ -161,17 +159,18 @@ class BackupRestoreViewModel(application: Application): AndroidViewModel(applica val backupPassphrase = MutableLiveData(null) val processingBackupFile = MutableLiveData(false) - val backupImportResult = MutableLiveData(null) + val backupImportResult = MutableLiveData(null) fun tryRestoreBackup() = viewModelScope.launch { - if (backupImportResult.value == BackupImportResult.SUCCESS) return@launch + if (processingBackupFile.value == true) return@launch + if (backupImportResult.value == BackupRestoreResult.SUCCESS) return@launch if (!validateData(backupFile.value, backupPassphrase.value)) return@launch val context = getApplication() val backupFile = backupFile.value!! val passphrase = backupPassphrase.value!! - val result: BackupImportResult + val result: BackupRestoreResult processingBackupFile.value = true @@ -199,13 +198,13 @@ class BackupRestoreViewModel(application: Application): AndroidViewModel(applica HomeActivity.requestResetAllSessionsOnStartup(context) - BackupImportResult.SUCCESS + BackupRestoreResult.SUCCESS } catch (e: DatabaseDowngradeException) { Log.w(TAG, "Failed due to the backup being from a newer version of Signal.", e) - BackupImportResult.FAILURE_VERSION_DOWNGRADE + BackupRestoreResult.FAILURE_VERSION_DOWNGRADE } catch (e: Exception) { Log.w(TAG, e) - BackupImportResult.FAILURE_UNKNOWN + BackupRestoreResult.FAILURE_UNKNOWN } } @@ -214,7 +213,7 @@ class BackupRestoreViewModel(application: Application): AndroidViewModel(applica backupImportResult.value = result } - enum class BackupImportResult { + enum class BackupRestoreResult { SUCCESS, FAILURE_VERSION_DOWNGRADE, FAILURE_UNKNOWN } } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/utilities/ViewUtilities.kt b/src/org/thoughtcrime/securesms/loki/utilities/ViewUtilities.kt index 73a6bef4e4..c9d135ba24 100644 --- a/src/org/thoughtcrime/securesms/loki/utilities/ViewUtilities.kt +++ b/src/org/thoughtcrime/securesms/loki/utilities/ViewUtilities.kt @@ -37,12 +37,10 @@ fun View.animateSizeChange(@DimenRes startSizeID: Int, @DimenRes endSizeID: Int, fun View.fadeIn(duration: Long = 150) { visibility = View.VISIBLE - animate().cancel() animate().setDuration(duration).alpha(1.0f).start() } fun View.fadeOut(duration: Long = 150) { - animate().cancel() animate().setDuration(duration).alpha(0.0f).setListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { super.onAnimationEnd(animation) diff --git a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java index 541f1b2018..8a31990537 100644 --- a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java +++ b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java @@ -147,7 +147,7 @@ public class TextSecurePreferences { private static final String ACTIVE_SIGNED_PRE_KEY_ID = "pref_active_signed_pre_key_id"; private static final String NEXT_SIGNED_PRE_KEY_ID = "pref_next_signed_pre_key_id"; - public static final String BACKUP_ENABLED = "pref_backup_enabled_v2"; + public static final String BACKUP_ENABLED = "pref_backup_enabled_v3"; private static final String BACKUP_PASSPHRASE = "pref_backup_passphrase"; private static final String ENCRYPTED_BACKUP_PASSPHRASE = "pref_encrypted_backup_passphrase"; private static final String BACKUP_TIME = "pref_backup_next_time"; @@ -1371,7 +1371,7 @@ public class TextSecurePreferences { String prefKey) { String value = prefs.getString(prefKey, null); if (value == null) { - backupEntryLog(prefKey, false); + logBackupEntry(prefKey, false); return; } outPrefList.add(BackupProtos.SharedPreference.newBuilder() @@ -1379,7 +1379,7 @@ public class TextSecurePreferences { .setKey(prefKey) .setValue(value) .build()); - backupEntryLog(prefKey, true); + logBackupEntry(prefKey, true); } private static void addBackupEntryInt( @@ -1389,7 +1389,7 @@ public class TextSecurePreferences { String prefKey) { int value = prefs.getInt(prefKey, -1); if (value == -1) { - backupEntryLog(prefKey, false); + logBackupEntry(prefKey, false); return; } outPrefList.add(BackupProtos.SharedPreference.newBuilder() @@ -1397,7 +1397,7 @@ public class TextSecurePreferences { .setKey(PREF_PREFIX_TYPE_INT + prefKey) // The prefix denotes the type of the preference. .setValue(String.valueOf(value)) .build()); - backupEntryLog(prefKey, true); + logBackupEntry(prefKey, true); } private static void addBackupEntryBoolean( @@ -1406,7 +1406,7 @@ public class TextSecurePreferences { String prefFileName, String prefKey) { if (!prefs.contains(prefKey)) { - backupEntryLog(prefKey, false); + logBackupEntry(prefKey, false); return; } outPrefList.add(BackupProtos.SharedPreference.newBuilder() @@ -1414,10 +1414,10 @@ public class TextSecurePreferences { .setKey(PREF_PREFIX_TYPE_BOOLEAN + prefKey) // The prefix denotes the type of the preference. .setValue(String.valueOf(prefs.getBoolean(prefKey, false))) .build()); - backupEntryLog(prefKey, true); + logBackupEntry(prefKey, true); } - private static void backupEntryLog(String prefName, boolean wasIncluded) { + private static void logBackupEntry(String prefName, boolean wasIncluded) { StringBuilder sb = new StringBuilder(); sb.append("Backup preference "); sb.append(wasIncluded ? "+ " : "- ");