Clear partially recovered shards from shared preferences when recovered

This commit is contained in:
ameba23
2021-06-25 09:03:58 +02:00
parent 3d807d9950
commit ef05ecc342
2 changed files with 9 additions and 12 deletions

View File

@@ -156,13 +156,6 @@ class OwnerReturnShardViewModel extends AndroidViewModel
ioExecutor.execute(() -> { ioExecutor.execute(() -> {
task.start(this, getWifiIpv4Address()); task.start(this, getWifiIpv4Address());
}); });
// KeyAgreementTask oldTask = task;
// KeyAgreementTask newTask = keyAgreementTaskProvider.get();
// task = newTask;
// ioExecutor.execute(() -> {
// if (oldTask != null) oldTask.stopListening();
// newTask.listen();
// });
} }
@UiThread @UiThread
@@ -230,9 +223,7 @@ class OwnerReturnShardViewModel extends AndroidViewModel
this.state.postValue(state); this.state.postValue(state);
}); });
} else if (state instanceof SecretOwnerTask.State.Success) { } else if (state instanceof SecretOwnerTask.State.Success) {
// startClicked.setEvent(true);
this.state.postValue(state); this.state.postValue(state);
// TODO do same for failure
} else { } else {
this.state.postValue(state); this.state.postValue(state);
} }

View File

@@ -1,6 +1,8 @@
package org.briarproject.briar.android.socialbackup.recover; package org.briarproject.briar.android.socialbackup.recover;
import android.app.Application; import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import org.briarproject.bramble.api.account.AccountManager; import org.briarproject.bramble.api.account.AccountManager;
import org.briarproject.bramble.api.contact.ContactManager; import org.briarproject.bramble.api.contact.ContactManager;
@@ -45,27 +47,27 @@ class RestoreAccountViewModel extends AndroidViewModel {
new MutableLiveData<>(false); new MutableLiveData<>(false);
private final AccountManager accountManager; private final AccountManager accountManager;
private final ContactManager contactManager;
private final Executor ioExecutor; private final Executor ioExecutor;
private final PasswordStrengthEstimator strengthEstimator; private final PasswordStrengthEstimator strengthEstimator;
private final DozeHelper dozeHelper; private final DozeHelper dozeHelper;
private final RestoreAccount restoreAccount; private final RestoreAccount restoreAccount;
private final SharedPreferences prefs;
@Inject @Inject
RestoreAccountViewModel(Application app, RestoreAccountViewModel(Application app,
AccountManager accountManager, AccountManager accountManager,
ContactManager contactManager,
RestoreAccount restoreAccount, RestoreAccount restoreAccount,
@IoExecutor Executor ioExecutor, @IoExecutor Executor ioExecutor,
PasswordStrengthEstimator strengthEstimator, PasswordStrengthEstimator strengthEstimator,
DozeHelper dozeHelper) { DozeHelper dozeHelper) {
super(app); super(app);
this.accountManager = accountManager; this.accountManager = accountManager;
this.contactManager = contactManager;
this.ioExecutor = ioExecutor; this.ioExecutor = ioExecutor;
this.strengthEstimator = strengthEstimator; this.strengthEstimator = strengthEstimator;
this.dozeHelper = dozeHelper; this.dozeHelper = dozeHelper;
this.restoreAccount = restoreAccount; this.restoreAccount = restoreAccount;
this.prefs = app.getSharedPreferences("account-recovery",
Context.MODE_PRIVATE);
ioExecutor.execute(() -> { ioExecutor.execute(() -> {
if (accountManager.accountExists()) { if (accountManager.accountExists()) {
@@ -123,6 +125,10 @@ class RestoreAccountViewModel extends AndroidViewModel {
LOG.warning("Cannot retrieve social backup"); LOG.warning("Cannot retrieve social backup");
state.postEvent(State.FAILED); state.postEvent(State.FAILED);
} }
// Remove partial recovery from shared preferences
prefs.edit().clear().apply();
state.postEvent(State.CREATED); state.postEvent(State.CREATED);
} else { } else {
LOG.warning("Failed to create account"); LOG.warning("Failed to create account");