Backup enabled preference flag reset.

General backup restore cleanup.
pull/375/head
Anton Chekulaev 4 years ago
parent 072f93afa1
commit ae15c4dd9f

@ -90,6 +90,8 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0' implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx: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") { implementation ("com.google.firebase:firebase-messaging:18.0.0") {
exclude group: 'com.google.firebase', module: 'firebase-core' exclude group: 'com.google.firebase', module: 'firebase-core'
@ -159,8 +161,6 @@ dependencies {
implementation "com.squareup.okhttp3:okhttp:3.12.1" implementation "com.squareup.okhttp3:okhttp:3.12.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9' 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:$kovenant_version"
implementation "nl.komponents.kovenant:kovenant-android:$kovenant_version" implementation "nl.komponents.kovenant:kovenant-android:$kovenant_version"
implementation "com.github.lelloman:android-identicons:v11" implementation "com.github.lelloman:android-identicons:v11"

@ -36,8 +36,6 @@ import org.thoughtcrime.securesms.backup.FullBackupImporter.DatabaseDowngradeExc
import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider
import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.logging.Log 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.setUpActionBarSessionLogo
import org.thoughtcrime.securesms.loki.utilities.show import org.thoughtcrime.securesms.loki.utilities.show
import org.thoughtcrime.securesms.notifications.NotificationChannels import org.thoughtcrime.securesms.notifications.NotificationChannels
@ -92,14 +90,14 @@ class BackupRestoreActivity : BaseActionBarActivity() {
// React to backup import result. // React to backup import result.
viewModel.backupImportResult.observe(this) { result -> viewModel.backupImportResult.observe(this) { result ->
if (result != null) when (result) { if (result != null) when (result) {
BackupRestoreViewModel.BackupImportResult.SUCCESS -> { BackupRestoreViewModel.BackupRestoreResult.SUCCESS -> {
val intent = Intent(this, HomeActivity::class.java) val intent = Intent(this, HomeActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
this.show(intent) 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() 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() 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<String>(null) val backupPassphrase = MutableLiveData<String>(null)
val processingBackupFile = MutableLiveData<Boolean>(false) val processingBackupFile = MutableLiveData<Boolean>(false)
val backupImportResult = MutableLiveData<BackupImportResult>(null) val backupImportResult = MutableLiveData<BackupRestoreResult>(null)
fun tryRestoreBackup() = viewModelScope.launch { 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 if (!validateData(backupFile.value, backupPassphrase.value)) return@launch
val context = getApplication<Application>() val context = getApplication<Application>()
val backupFile = backupFile.value!! val backupFile = backupFile.value!!
val passphrase = backupPassphrase.value!! val passphrase = backupPassphrase.value!!
val result: BackupImportResult val result: BackupRestoreResult
processingBackupFile.value = true processingBackupFile.value = true
@ -199,13 +198,13 @@ class BackupRestoreViewModel(application: Application): AndroidViewModel(applica
HomeActivity.requestResetAllSessionsOnStartup(context) HomeActivity.requestResetAllSessionsOnStartup(context)
BackupImportResult.SUCCESS BackupRestoreResult.SUCCESS
} catch (e: DatabaseDowngradeException) { } catch (e: DatabaseDowngradeException) {
Log.w(TAG, "Failed due to the backup being from a newer version of Signal.", e) 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) { } catch (e: Exception) {
Log.w(TAG, e) Log.w(TAG, e)
BackupImportResult.FAILURE_UNKNOWN BackupRestoreResult.FAILURE_UNKNOWN
} }
} }
@ -214,7 +213,7 @@ class BackupRestoreViewModel(application: Application): AndroidViewModel(applica
backupImportResult.value = result backupImportResult.value = result
} }
enum class BackupImportResult { enum class BackupRestoreResult {
SUCCESS, FAILURE_VERSION_DOWNGRADE, FAILURE_UNKNOWN SUCCESS, FAILURE_VERSION_DOWNGRADE, FAILURE_UNKNOWN
} }
} }

@ -37,12 +37,10 @@ fun View.animateSizeChange(@DimenRes startSizeID: Int, @DimenRes endSizeID: Int,
fun View.fadeIn(duration: Long = 150) { fun View.fadeIn(duration: Long = 150) {
visibility = View.VISIBLE visibility = View.VISIBLE
animate().cancel()
animate().setDuration(duration).alpha(1.0f).start() animate().setDuration(duration).alpha(1.0f).start()
} }
fun View.fadeOut(duration: Long = 150) { fun View.fadeOut(duration: Long = 150) {
animate().cancel()
animate().setDuration(duration).alpha(0.0f).setListener(object : AnimatorListenerAdapter() { animate().setDuration(duration).alpha(0.0f).setListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) { override fun onAnimationEnd(animation: Animator?) {
super.onAnimationEnd(animation) super.onAnimationEnd(animation)

@ -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 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"; 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 BACKUP_PASSPHRASE = "pref_backup_passphrase";
private static final String ENCRYPTED_BACKUP_PASSPHRASE = "pref_encrypted_backup_passphrase"; private static final String ENCRYPTED_BACKUP_PASSPHRASE = "pref_encrypted_backup_passphrase";
private static final String BACKUP_TIME = "pref_backup_next_time"; private static final String BACKUP_TIME = "pref_backup_next_time";
@ -1371,7 +1371,7 @@ public class TextSecurePreferences {
String prefKey) { String prefKey) {
String value = prefs.getString(prefKey, null); String value = prefs.getString(prefKey, null);
if (value == null) { if (value == null) {
backupEntryLog(prefKey, false); logBackupEntry(prefKey, false);
return; return;
} }
outPrefList.add(BackupProtos.SharedPreference.newBuilder() outPrefList.add(BackupProtos.SharedPreference.newBuilder()
@ -1379,7 +1379,7 @@ public class TextSecurePreferences {
.setKey(prefKey) .setKey(prefKey)
.setValue(value) .setValue(value)
.build()); .build());
backupEntryLog(prefKey, true); logBackupEntry(prefKey, true);
} }
private static void addBackupEntryInt( private static void addBackupEntryInt(
@ -1389,7 +1389,7 @@ public class TextSecurePreferences {
String prefKey) { String prefKey) {
int value = prefs.getInt(prefKey, -1); int value = prefs.getInt(prefKey, -1);
if (value == -1) { if (value == -1) {
backupEntryLog(prefKey, false); logBackupEntry(prefKey, false);
return; return;
} }
outPrefList.add(BackupProtos.SharedPreference.newBuilder() 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. .setKey(PREF_PREFIX_TYPE_INT + prefKey) // The prefix denotes the type of the preference.
.setValue(String.valueOf(value)) .setValue(String.valueOf(value))
.build()); .build());
backupEntryLog(prefKey, true); logBackupEntry(prefKey, true);
} }
private static void addBackupEntryBoolean( private static void addBackupEntryBoolean(
@ -1406,7 +1406,7 @@ public class TextSecurePreferences {
String prefFileName, String prefFileName,
String prefKey) { String prefKey) {
if (!prefs.contains(prefKey)) { if (!prefs.contains(prefKey)) {
backupEntryLog(prefKey, false); logBackupEntry(prefKey, false);
return; return;
} }
outPrefList.add(BackupProtos.SharedPreference.newBuilder() 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. .setKey(PREF_PREFIX_TYPE_BOOLEAN + prefKey) // The prefix denotes the type of the preference.
.setValue(String.valueOf(prefs.getBoolean(prefKey, false))) .setValue(String.valueOf(prefs.getBoolean(prefKey, false)))
.build()); .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(); StringBuilder sb = new StringBuilder();
sb.append("Backup preference "); sb.append("Backup preference ");
sb.append(wasIncluded ? "+ " : "- "); sb.append(wasIncluded ? "+ " : "- ");

Loading…
Cancel
Save