Merge branch '2311-remind-to-wipe' into 'master'

Remind user to wipe mailbox if it's unreachable when unpairing

Closes #2311

See merge request briar/briar!1639
This commit is contained in:
akwizgran
2022-04-27 17:00:12 +00:00
8 changed files with 65 additions and 6 deletions

View File

@@ -45,7 +45,11 @@ public interface MailboxManager {
/**
* Unpairs the owner's mailbox and tries to wipe it.
* As this makes a network call, it should be run on the {@link IoExecutor}.
*
* @return true if we could wipe the mailbox, false if we couldn't.
* It is advised to inform the user to wipe the mailbox themselves,
* if we failed to wipe it.
*/
@IoExecutor
void unPair() throws DbException;
boolean unPair() throws DbException;
}

View File

@@ -7,6 +7,7 @@ import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
import org.briarproject.bramble.api.mailbox.MailboxFileId;
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.io.File;
import java.io.IOException;
@@ -16,6 +17,7 @@ import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
@NotNullByDefault
interface MailboxApi {
/**

View File

@@ -102,6 +102,7 @@ class MailboxManagerImpl implements MailboxManager {
try {
MailboxProperties props = db.transactionWithNullableResult(true,
mailboxSettingsManager::getOwnMailboxProperties);
if (props == null) throw new DbException();
success = api.checkStatus(props);
} catch (DbException e) {
logException(LOG, WARNING, e);
@@ -132,17 +133,24 @@ class MailboxManagerImpl implements MailboxManager {
}
@Override
public void unPair() throws DbException {
public boolean unPair() throws DbException {
MailboxProperties properties = db.transactionWithNullableResult(true,
mailboxSettingsManager::getOwnMailboxProperties);
if (properties == null) {
// no more mailbox, that's strange but possible if called in quick
// succession, so let's return true this time
return true;
}
boolean wasWiped;
try {
api.wipeMailbox(properties);
wasWiped = true;
} catch (IOException | MailboxApi.ApiException e) {
// We wipe on a best-effort basis.
// If we can't do it, we still unpair.
logException(LOG, WARNING, e);
wasWiped = false;
}
db.transaction(false,
mailboxSettingsManager::removeOwnMailboxProperties);
return wasWiped;
}
}

View File

@@ -11,10 +11,12 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.fragment.FinalFragment;
import org.briarproject.briar.android.view.BlankFragment;
import javax.inject.Inject;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
@@ -68,6 +70,9 @@ public class MailboxActivity extends BriarActivity {
onCameraError();
} else if (state instanceof MailboxState.IsPaired) {
onIsPaired(((MailboxState.IsPaired) state).isOnline);
} else if (state instanceof MailboxState.WasUnpaired) {
MailboxState.WasUnpaired s = (MailboxState.WasUnpaired) state;
onUnPaired(s.tellUserToWipeMailbox);
} else {
throw new AssertionError("Unknown state: " + state);
}
@@ -190,4 +195,22 @@ public class MailboxActivity extends BriarActivity {
showFragment(getSupportFragmentManager(), f, tag, false);
}
private void onUnPaired(boolean tellUserToWipeMailbox) {
if (tellUserToWipeMailbox) {
showFragment(getSupportFragmentManager(), new BlankFragment(),
BlankFragment.TAG);
AlertDialog.Builder builder =
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
builder.setTitle(R.string.mailbox_status_unlink_no_wipe_title);
builder.setMessage(R.string.mailbox_status_unlink_no_wipe_message);
builder.setNeutralButton(R.string.got_it,
(dialog, which) -> dialog.cancel());
builder.setOnCancelListener(
dialog -> supportFinishAfterTransition());
builder.show();
} else {
supportFinishAfterTransition();
}
}
}

View File

@@ -35,4 +35,12 @@ class MailboxState {
}
}
static class WasUnpaired extends MailboxState {
final boolean tellUserToWipeMailbox;
WasUnpaired(boolean tellUserToWipeMailbox) {
this.tellUserToWipeMailbox = tellUserToWipeMailbox;
}
}
}

View File

@@ -225,8 +225,8 @@ class MailboxViewModel extends DbViewModel
void unlink() {
ioExecutor.execute(() -> {
try {
mailboxManager.unPair();
pairingState.postEvent(new MailboxState.NotSetup());
boolean wasWiped = mailboxManager.unPair();
pairingState.postEvent(new MailboxState.WasUnpaired(!wasWiped));
} catch (DbException e) {
handleException(e);
}

View File

@@ -0,0 +1,12 @@
package org.briarproject.briar.android.view;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import androidx.fragment.app.Fragment;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class BlankFragment extends Fragment {
public static final String TAG = BlankFragment.class.getName();
}

View File

@@ -654,6 +654,8 @@
<string name="mailbox_status_unlink_dialog_title">Unlink mailbox?</string>
<string name="mailbox_status_unlink_dialog_question">Are you sure you want to unlink your Mailbox?</string>
<string name="mailbox_status_unlink_dialog_warning">If you unlink your Mailbox, you won\'t be able to receive messages while Briar is offline.</string>
<string name="mailbox_status_unlink_no_wipe_title">Your Mailbox has been unlinked</string>
<string name="mailbox_status_unlink_no_wipe_message">Next time you have access to your Mailbox device, please open the Mailbox app and tap the \"Unlink\" button to complete the process.\n\nIf you no longer have access to your Mailbox device, don\'t worry. Your data is encrypted so it will remain secure even if you don\'t complete the process.</string>
<!-- Conversation Settings -->
<string name="disappearing_messages_title">Disappearing messages</string>