mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Merge branch '2397-wrong-type-of-qr-code' into 'master'
Show appropriate error message if user scans wrong kind of QR code Closes #2397 See merge request briar/briar!1748
This commit is contained in:
@@ -3,12 +3,14 @@ package org.briarproject.briar.android.contact.add.nearby;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.qrcode.QrCodeClassifier.QrCodeType;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
abstract class AddContactState {
|
||||
|
||||
static class KeyAgreementListening extends AddContactState {
|
||||
|
||||
final Bitmap qrCode;
|
||||
|
||||
KeyAgreementListening(Bitmap qrCode) {
|
||||
@@ -29,6 +31,7 @@ abstract class AddContactState {
|
||||
}
|
||||
|
||||
static class ContactExchangeFinished extends AddContactState {
|
||||
|
||||
final ContactExchangeResult result;
|
||||
|
||||
ContactExchangeFinished(ContactExchangeResult result) {
|
||||
@@ -37,25 +40,34 @@ abstract class AddContactState {
|
||||
}
|
||||
|
||||
static class Failed extends AddContactState {
|
||||
/**
|
||||
* Non-null if failed due to the scanned QR code version.
|
||||
* True if the app producing the code is too old.
|
||||
* False if the scanning app is too old.
|
||||
*/
|
||||
@Nullable
|
||||
final Boolean qrCodeTooOld;
|
||||
|
||||
Failed(@Nullable Boolean qrCodeTooOld) {
|
||||
this.qrCodeTooOld = qrCodeTooOld;
|
||||
static class WrongQrCodeType extends Failed {
|
||||
|
||||
final QrCodeType qrCodeType;
|
||||
|
||||
WrongQrCodeType(QrCodeType qrCodeType) {
|
||||
this.qrCodeType = qrCodeType;
|
||||
}
|
||||
}
|
||||
|
||||
Failed() {
|
||||
this(null);
|
||||
static class WrongQrCodeVersion extends Failed {
|
||||
|
||||
/**
|
||||
* True if the app producing the code is too old.
|
||||
* False if the scanning app is too old.
|
||||
*/
|
||||
final boolean qrCodeTooOld;
|
||||
|
||||
WrongQrCodeVersion(boolean qrCodeTooOld) {
|
||||
this.qrCodeTooOld = qrCodeTooOld;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract static class ContactExchangeResult {
|
||||
|
||||
static class Success extends ContactExchangeResult {
|
||||
|
||||
final Author remoteAuthor;
|
||||
|
||||
Success(Author remoteAuthor) {
|
||||
@@ -64,6 +76,7 @@ abstract class AddContactState {
|
||||
}
|
||||
|
||||
static class Error extends ContactExchangeResult {
|
||||
|
||||
@Nullable
|
||||
final Author duplicateAuthor;
|
||||
|
||||
|
||||
@@ -6,12 +6,15 @@ import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.qrcode.QrCodeClassifier.QrCodeType;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.ContactExchangeFinished;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.ContactExchangeResult;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.Failed;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.Failed.WrongQrCodeType;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.Failed.WrongQrCodeVersion;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddNearbyContactViewModel.BluetoothDecision;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
@@ -34,6 +37,7 @@ import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
import static android.widget.Toast.LENGTH_LONG;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.qrcode.QrCodeClassifier.QrCodeType.MAILBOX;
|
||||
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactViewModel.BluetoothDecision.ACCEPTED;
|
||||
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactViewModel.BluetoothDecision.REFUSED;
|
||||
|
||||
@@ -141,9 +145,15 @@ public class AddNearbyContactActivity extends BriarActivity
|
||||
ContactExchangeResult result =
|
||||
((ContactExchangeFinished) state).result;
|
||||
onContactExchangeResult(result);
|
||||
} else if (state instanceof WrongQrCodeType) {
|
||||
QrCodeType qrCodeType = ((WrongQrCodeType) state).qrCodeType;
|
||||
if (qrCodeType == MAILBOX) onMailboxQrCodeScanned();
|
||||
else onWrongQrCodeType();
|
||||
} else if (state instanceof WrongQrCodeVersion) {
|
||||
boolean qrCodeTooOld = ((WrongQrCodeVersion) state).qrCodeTooOld;
|
||||
onWrongQrCodeVersion(qrCodeTooOld);
|
||||
} else if (state instanceof Failed) {
|
||||
Boolean qrCodeTooOld = ((Failed) state).qrCodeTooOld;
|
||||
onAddingContactFailed(qrCodeTooOld);
|
||||
showErrorFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,15 +180,27 @@ public class AddNearbyContactActivity extends BriarActivity
|
||||
} else throw new AssertionError();
|
||||
}
|
||||
|
||||
private void onAddingContactFailed(@Nullable Boolean qrCodeTooOld) {
|
||||
if (qrCodeTooOld == null) {
|
||||
showErrorFragment();
|
||||
} else {
|
||||
String msg;
|
||||
if (qrCodeTooOld) msg = getString(R.string.qr_code_too_old_1);
|
||||
else msg = getString(R.string.qr_code_too_new_1);
|
||||
showNextFragment(AddNearbyContactErrorFragment.newInstance(msg));
|
||||
}
|
||||
private void onMailboxQrCodeScanned() {
|
||||
String title = getString(R.string.qr_code_invalid);
|
||||
String msg = getString(R.string.mailbox_qr_code_for_contact);
|
||||
showNextFragment(
|
||||
AddNearbyContactErrorFragment.newInstance(title, msg, false));
|
||||
}
|
||||
|
||||
private void onWrongQrCodeType() {
|
||||
String title = getString(R.string.qr_code_invalid);
|
||||
String msg = getString(R.string.qr_code_format_unknown);
|
||||
showNextFragment(
|
||||
AddNearbyContactErrorFragment.newInstance(title, msg, false));
|
||||
}
|
||||
|
||||
private void onWrongQrCodeVersion(boolean qrCodeTooOld) {
|
||||
String title = getString(R.string.qr_code_invalid);
|
||||
String msg;
|
||||
if (qrCodeTooOld) msg = getString(R.string.qr_code_too_old_1);
|
||||
else msg = getString(R.string.qr_code_too_new_1);
|
||||
showNextFragment(
|
||||
AddNearbyContactErrorFragment.newInstance(title, msg, false));
|
||||
}
|
||||
|
||||
private void showErrorFragment() {
|
||||
|
||||
@@ -22,6 +22,7 @@ import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
import static android.view.View.GONE;
|
||||
import static org.briarproject.briar.android.util.UiUtils.hideViewOnSmallScreen;
|
||||
import static org.briarproject.briar.android.util.UiUtils.onSingleLinkClick;
|
||||
|
||||
@@ -31,17 +32,22 @@ public class AddNearbyContactErrorFragment extends BaseFragment {
|
||||
|
||||
public static final String TAG =
|
||||
AddNearbyContactErrorFragment.class.getName();
|
||||
private static final String ERROR_MSG = "errorMessage";
|
||||
private static final String ARG_TITLE = "title";
|
||||
private static final String ARG_ERROR_MSG = "message";
|
||||
private static final String ARG_FEEDBACK = "feedback";
|
||||
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
|
||||
private AddNearbyContactViewModel viewModel;
|
||||
|
||||
public static AddNearbyContactErrorFragment newInstance(String errorMsg) {
|
||||
public static AddNearbyContactErrorFragment newInstance(String title,
|
||||
String errorMessage, boolean feedback) {
|
||||
AddNearbyContactErrorFragment f = new AddNearbyContactErrorFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ERROR_MSG, errorMsg);
|
||||
args.putString(ARG_TITLE, title);
|
||||
args.putString(ARG_ERROR_MSG, errorMessage);
|
||||
args.putBoolean(ARG_FEEDBACK, feedback);
|
||||
f.setArguments(args);
|
||||
return f;
|
||||
}
|
||||
@@ -66,19 +72,32 @@ public class AddNearbyContactErrorFragment extends BaseFragment {
|
||||
View v = inflater.inflate(R.layout.fragment_error_contact_exchange,
|
||||
container, false);
|
||||
|
||||
// set optional error message
|
||||
TextView explanation = v.findViewById(R.id.errorMessage);
|
||||
String title = null, errorMessage = null;
|
||||
boolean feedback = true;
|
||||
Bundle args = getArguments();
|
||||
String errorMessage = args == null ? null : args.getString(ERROR_MSG);
|
||||
if (errorMessage == null) {
|
||||
explanation.setText(getString(R.string.add_contact_error_two_way));
|
||||
} else {
|
||||
explanation.setText(args.getString(ERROR_MSG));
|
||||
if (args != null) {
|
||||
title = args.getString(ARG_TITLE);
|
||||
errorMessage = args.getString(ARG_ERROR_MSG);
|
||||
feedback = args.getBoolean(ARG_FEEDBACK, true);
|
||||
}
|
||||
|
||||
if (title != null) {
|
||||
TextView titleView = v.findViewById(R.id.errorTitle);
|
||||
titleView.setText(title);
|
||||
}
|
||||
|
||||
if (errorMessage != null) {
|
||||
TextView messageView = v.findViewById(R.id.errorMessage);
|
||||
messageView.setText(errorMessage);
|
||||
}
|
||||
|
||||
// make feedback link clickable
|
||||
TextView sendFeedback = v.findViewById(R.id.sendFeedback);
|
||||
onSingleLinkClick(sendFeedback, this::triggerFeedback);
|
||||
if (feedback) {
|
||||
// make feedback link clickable
|
||||
onSingleLinkClick(sendFeedback, this::triggerFeedback);
|
||||
} else {
|
||||
sendFeedback.setVisibility(GONE);
|
||||
}
|
||||
|
||||
// buttons
|
||||
Button tryAgain = v.findViewById(R.id.tryAgainButton);
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.briarproject.bramble.api.plugin.PluginManager;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportStateEvent;
|
||||
import org.briarproject.bramble.api.qrcode.WrongQrCodeTypeException;
|
||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||
import org.briarproject.bramble.plugin.bluetooth.BluetoothPlugin;
|
||||
import org.briarproject.briar.R;
|
||||
@@ -50,9 +51,13 @@ import org.briarproject.briar.android.contact.add.nearby.AddContactState.Contact
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.ContactExchangeResult.Error;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.ContactExchangeResult.Success;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.ContactExchangeStarted;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.Failed;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.Failed.WrongQrCodeType;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.Failed.WrongQrCodeVersion;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.KeyAgreementListening;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.KeyAgreementStarted;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.KeyAgreementWaiting;
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddContactState.QrCodeScanned;
|
||||
import org.briarproject.briar.android.qrcode.QrCodeDecoder;
|
||||
import org.briarproject.briar.android.qrcode.QrCodeUtils;
|
||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||
@@ -60,7 +65,6 @@ import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -85,6 +89,7 @@ import static org.briarproject.bramble.api.plugin.Plugin.State.DISABLED;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.INACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.StringUtils.ISO_8859_1;
|
||||
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactPermissionManager.areEssentialPermissionsGranted;
|
||||
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactViewModel.BluetoothDecision.NO_ADAPTER;
|
||||
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactViewModel.BluetoothDecision.REFUSED;
|
||||
@@ -126,9 +131,6 @@ class AddNearbyContactViewModel extends AndroidViewModel
|
||||
REFUSED
|
||||
}
|
||||
|
||||
@SuppressWarnings("CharsetObjectCanBeUsed") // Requires minSdkVersion >= 19
|
||||
private static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
|
||||
|
||||
private final EventBus eventBus;
|
||||
private final AndroidExecutor androidExecutor;
|
||||
private final Executor ioExecutor;
|
||||
@@ -376,11 +378,11 @@ class AddNearbyContactViewModel extends AndroidViewModel
|
||||
} else if (e instanceof KeyAgreementAbortedEvent) {
|
||||
LOG.info("KeyAgreementAbortedEvent received");
|
||||
resetPayloadFlags();
|
||||
state.setValue(new AddContactState.Failed());
|
||||
state.setValue(new Failed());
|
||||
} else if (e instanceof KeyAgreementFailedEvent) {
|
||||
LOG.info("KeyAgreementFailedEvent received");
|
||||
resetPayloadFlags();
|
||||
state.setValue(new AddContactState.Failed());
|
||||
state.setValue(new Failed());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,22 +448,22 @@ class AddNearbyContactViewModel extends AndroidViewModel
|
||||
// Ignore results until the KeyAgreementTask is ready
|
||||
if (!gotLocalPayload || gotRemotePayload || currentTask == null) return;
|
||||
try {
|
||||
byte[] payloadBytes = result.getText().getBytes(ISO_8859_1);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Remote payload is " + payloadBytes.length + " bytes");
|
||||
Payload remotePayload = payloadParser.parse(payloadBytes);
|
||||
Payload remotePayload = payloadParser.parse(result.getText());
|
||||
gotRemotePayload = true;
|
||||
currentTask.connectAndRunProtocol(remotePayload);
|
||||
state.postValue(new AddContactState.QrCodeScanned());
|
||||
state.postValue(new QrCodeScanned());
|
||||
} catch (WrongQrCodeTypeException e) {
|
||||
resetPayloadFlags();
|
||||
state.postValue(new WrongQrCodeType(e.getQrCodeType()));
|
||||
} catch (UnsupportedVersionException e) {
|
||||
resetPayloadFlags();
|
||||
state.postValue(new AddContactState.Failed(e.isTooOld()));
|
||||
state.postValue(new WrongQrCodeVersion(e.isTooOld()));
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
LOG.log(WARNING, "QR Code Invalid", e);
|
||||
androidExecutor.runOnUiThread(() -> Toast.makeText(getApplication(),
|
||||
R.string.qr_code_invalid, LENGTH_LONG).show());
|
||||
resetPayloadFlags();
|
||||
state.postValue(new AddContactState.Failed());
|
||||
state.postValue(new Failed());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -436,7 +436,7 @@ class HotspotManager {
|
||||
}
|
||||
|
||||
private static String createWifiLoginString(String ssid, String password) {
|
||||
// https://en.wikipedia.org/wiki/QR_code#WiFi_network_login
|
||||
// https://en.wikipedia.org/wiki/QR_code#Joining_a_Wi%E2%80%91Fi_network
|
||||
// do not remove the dangling ';', it can cause problems to omit it
|
||||
return "WIFI:S:" + ssid + ";T:WPA;P:" + password + ";;";
|
||||
}
|
||||
|
||||
@@ -6,10 +6,24 @@ import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.bramble.api.mailbox.MailboxPairingState;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxPairingState.ConnectionError;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxPairingState.InvalidQrCode;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxPairingState.MailboxAlreadyPaired;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxPairingState.Paired;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxPairingState.Pending;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxPairingState.UnexpectedError;
|
||||
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.mailbox.MailboxState.CameraError;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.IsPaired;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.NotSetup;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.OfflineWhenPairing;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.Pairing;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.ScanningQrCode;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.ShowDownload;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.WasUnpaired;
|
||||
import org.briarproject.briar.android.view.BlankFragment;
|
||||
import org.briarproject.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.nullsafety.ParametersNotNullByDefault;
|
||||
@@ -25,6 +39,9 @@ import androidx.lifecycle.ViewModelProvider;
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.widget.Toast.LENGTH_LONG;
|
||||
import static org.briarproject.bramble.api.mailbox.MailboxConstants.QR_FORMAT_VERSION;
|
||||
import static org.briarproject.bramble.api.qrcode.QrCodeClassifier.QrCodeType.BQP;
|
||||
import static org.briarproject.bramble.api.qrcode.QrCodeClassifier.QrCodeType.MAILBOX;
|
||||
import static org.briarproject.briar.android.util.UiUtils.showFragment;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -56,24 +73,23 @@ public class MailboxActivity extends BriarActivity {
|
||||
}
|
||||
|
||||
viewModel.getPairingState().observeEvent(this, state -> {
|
||||
if (state instanceof MailboxState.NotSetup) {
|
||||
if (state instanceof NotSetup) {
|
||||
onNotSetup();
|
||||
} else if (state instanceof MailboxState.ShowDownload) {
|
||||
} else if (state instanceof ShowDownload) {
|
||||
onShowDownload();
|
||||
} else if (state instanceof MailboxState.ScanningQrCode) {
|
||||
} else if (state instanceof ScanningQrCode) {
|
||||
onScanningQrCode();
|
||||
} else if (state instanceof MailboxState.Pairing) {
|
||||
MailboxPairingState s =
|
||||
((MailboxState.Pairing) state).pairingState;
|
||||
} else if (state instanceof Pairing) {
|
||||
MailboxPairingState s = ((Pairing) state).pairingState;
|
||||
onMailboxPairingStateChanged(s);
|
||||
} else if (state instanceof MailboxState.OfflineWhenPairing) {
|
||||
} else if (state instanceof OfflineWhenPairing) {
|
||||
onOffline();
|
||||
} else if (state instanceof MailboxState.CameraError) {
|
||||
} else if (state instanceof CameraError) {
|
||||
onCameraError();
|
||||
} else if (state instanceof MailboxState.IsPaired) {
|
||||
onIsPaired(((MailboxState.IsPaired) state).isOnline);
|
||||
} else if (state instanceof MailboxState.WasUnpaired) {
|
||||
MailboxState.WasUnpaired s = (MailboxState.WasUnpaired) state;
|
||||
} else if (state instanceof IsPaired) {
|
||||
onIsPaired(((IsPaired) state).isOnline);
|
||||
} else if (state instanceof WasUnpaired) {
|
||||
WasUnpaired s = (WasUnpaired) state;
|
||||
onUnPaired(s.tellUserToWipeMailbox);
|
||||
} else {
|
||||
throw new AssertionError("Unknown state: " + state);
|
||||
@@ -104,7 +120,7 @@ public class MailboxActivity extends BriarActivity {
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
MailboxState s = viewModel.getPairingState().getLastValue();
|
||||
if (s instanceof MailboxState.Pairing) {
|
||||
if (s instanceof Pairing) {
|
||||
// don't go back in the flow if we are already pairing
|
||||
// with the mailbox. We provide a try-again button instead.
|
||||
supportFinishAfterTransition();
|
||||
@@ -158,31 +174,44 @@ public class MailboxActivity extends BriarActivity {
|
||||
}
|
||||
Fragment f;
|
||||
String tag;
|
||||
if (s instanceof MailboxPairingState.Pending) {
|
||||
long timeStarted = ((MailboxPairingState.Pending) s).timeStarted;
|
||||
if (s instanceof Pending) {
|
||||
long timeStarted = ((Pending) s).timeStarted;
|
||||
f = MailboxConnectingFragment.newInstance(timeStarted);
|
||||
tag = MailboxConnectingFragment.TAG;
|
||||
} else if (s instanceof MailboxPairingState.InvalidQrCode) {
|
||||
f = ErrorFragment.newInstance(
|
||||
R.string.mailbox_setup_qr_code_wrong_title,
|
||||
R.string.mailbox_setup_qr_code_wrong_description);
|
||||
} else if (s instanceof InvalidQrCode) {
|
||||
InvalidQrCode i = (InvalidQrCode) s;
|
||||
int errorRes;
|
||||
if (i.qrCodeType == MAILBOX) {
|
||||
if (i.formatVersion < QR_FORMAT_VERSION) {
|
||||
errorRes = R.string.mailbox_qr_code_too_old;
|
||||
} else if (i.formatVersion > QR_FORMAT_VERSION) {
|
||||
errorRes = R.string.mailbox_qr_code_too_new;
|
||||
} else {
|
||||
errorRes = R.string.mailbox_setup_qr_code_wrong_description;
|
||||
}
|
||||
} else if (i.qrCodeType == BQP) {
|
||||
errorRes = R.string.contact_qr_code_for_mailbox;
|
||||
} else {
|
||||
errorRes = R.string.mailbox_setup_qr_code_wrong_description;
|
||||
}
|
||||
f = ErrorFragment.newInstance(R.string.qr_code_invalid, errorRes);
|
||||
tag = ErrorFragment.TAG;
|
||||
} else if (s instanceof MailboxPairingState.MailboxAlreadyPaired) {
|
||||
} else if (s instanceof MailboxAlreadyPaired) {
|
||||
f = ErrorFragment.newInstance(
|
||||
R.string.mailbox_setup_already_paired_title,
|
||||
R.string.mailbox_setup_already_paired_description);
|
||||
tag = ErrorFragment.TAG;
|
||||
} else if (s instanceof MailboxPairingState.ConnectionError) {
|
||||
} else if (s instanceof ConnectionError) {
|
||||
f = ErrorFragment.newInstance(
|
||||
R.string.mailbox_setup_io_error_title,
|
||||
R.string.mailbox_setup_io_error_description);
|
||||
tag = ErrorFragment.TAG;
|
||||
} else if (s instanceof MailboxPairingState.UnexpectedError) {
|
||||
} else if (s instanceof UnexpectedError) {
|
||||
f = ErrorFragment.newInstance(
|
||||
R.string.mailbox_setup_assertion_error_title,
|
||||
R.string.mailbox_setup_assertion_error_description);
|
||||
tag = ErrorFragment.TAG;
|
||||
} else if (s instanceof MailboxPairingState.Paired) {
|
||||
} else if (s instanceof Paired) {
|
||||
f = FinalFragment.newInstance(R.string.mailbox_setup_paired_title,
|
||||
R.drawable.ic_check_circle_outline,
|
||||
R.color.briar_brand_green,
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxManager;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxPairingState;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxPairingState.Paired;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxPairingTask;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxStatus;
|
||||
import org.briarproject.bramble.api.mailbox.event.OwnMailboxConnectionStatusEvent;
|
||||
@@ -24,7 +25,14 @@ import org.briarproject.bramble.api.plugin.TorConstants;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.CameraError;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.IsPaired;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.NotSetup;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.OfflineWhenPairing;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.Pairing;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.ScanningQrCode;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.ShowDownload;
|
||||
import org.briarproject.briar.android.mailbox.MailboxState.WasUnpaired;
|
||||
import org.briarproject.briar.android.qrcode.QrCodeDecoder;
|
||||
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||
@@ -113,7 +121,7 @@ class MailboxViewModel extends DbViewModel
|
||||
MailboxStatus mailboxStatus =
|
||||
mailboxManager.getMailboxStatus(txn);
|
||||
boolean isOnline = isTorActive();
|
||||
pairingState.postEvent(new MailboxState.IsPaired(isOnline));
|
||||
pairingState.postEvent(new IsPaired(isOnline));
|
||||
status.postValue(mailboxStatus);
|
||||
} else {
|
||||
pairingState.postEvent(new NotSetup());
|
||||
@@ -142,14 +150,14 @@ class MailboxViewModel extends DbViewModel
|
||||
@UiThread
|
||||
private void onTorInactive() {
|
||||
MailboxState lastState = pairingState.getLastValue();
|
||||
if (lastState instanceof MailboxState.IsPaired) {
|
||||
if (lastState instanceof IsPaired) {
|
||||
// we are already paired, so use IsPaired state
|
||||
pairingState.setEvent(new MailboxState.IsPaired(false));
|
||||
} else if (lastState instanceof MailboxState.Pairing) {
|
||||
MailboxState.Pairing p = (MailboxState.Pairing) lastState;
|
||||
pairingState.setEvent(new IsPaired(false));
|
||||
} else if (lastState instanceof Pairing) {
|
||||
Pairing p = (Pairing) lastState;
|
||||
// check that we not just finished pairing (showing success screen)
|
||||
if (!(p.pairingState instanceof MailboxPairingState.Paired)) {
|
||||
pairingState.setEvent(new MailboxState.OfflineWhenPairing());
|
||||
if (!(p.pairingState instanceof Paired)) {
|
||||
pairingState.setEvent(new OfflineWhenPairing());
|
||||
}
|
||||
// else ignore offline event as user will be leaving UI flow anyway
|
||||
}
|
||||
@@ -158,15 +166,15 @@ class MailboxViewModel extends DbViewModel
|
||||
@UiThread
|
||||
void onScanButtonClicked() {
|
||||
if (isTorActive()) {
|
||||
pairingState.setEvent(new MailboxState.ScanningQrCode());
|
||||
pairingState.setEvent(new ScanningQrCode());
|
||||
} else {
|
||||
pairingState.setEvent(new MailboxState.OfflineWhenPairing());
|
||||
pairingState.setEvent(new OfflineWhenPairing());
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void onCameraError() {
|
||||
pairingState.setEvent(new MailboxState.CameraError());
|
||||
pairingState.setEvent(new CameraError());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -182,7 +190,7 @@ class MailboxViewModel extends DbViewModel
|
||||
pairingTask = mailboxManager.startPairingTask(qrCodePayload);
|
||||
pairingTask.addObserver(this);
|
||||
} else {
|
||||
pairingState.postEvent(new MailboxState.OfflineWhenPairing());
|
||||
pairingState.postEvent(new OfflineWhenPairing());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +201,7 @@ class MailboxViewModel extends DbViewModel
|
||||
LOG.info("New pairing state: " +
|
||||
mailboxPairingState.getClass().getSimpleName());
|
||||
}
|
||||
pairingState.setEvent(new MailboxState.Pairing(mailboxPairingState));
|
||||
pairingState.setEvent(new Pairing(mailboxPairingState));
|
||||
}
|
||||
|
||||
private boolean isTorActive() {
|
||||
@@ -203,7 +211,7 @@ class MailboxViewModel extends DbViewModel
|
||||
|
||||
@UiThread
|
||||
void showDownloadFragment() {
|
||||
pairingState.setEvent(new MailboxState.ShowDownload());
|
||||
pairingState.setEvent(new ShowDownload());
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@@ -214,7 +222,7 @@ class MailboxViewModel extends DbViewModel
|
||||
@UiThread
|
||||
void checkIfOnlineWhenPaired() {
|
||||
boolean isOnline = isTorActive();
|
||||
pairingState.setEvent(new MailboxState.IsPaired(isOnline));
|
||||
pairingState.setEvent(new IsPaired(isOnline));
|
||||
}
|
||||
|
||||
LiveData<Boolean> checkConnection() {
|
||||
@@ -227,7 +235,7 @@ class MailboxViewModel extends DbViewModel
|
||||
checkConnection(success -> {
|
||||
boolean isOnline = isTorActive();
|
||||
// make UI move back to status fragment by changing pairingState
|
||||
pairingState.postEvent(new MailboxState.IsPaired(isOnline));
|
||||
pairingState.postEvent(new IsPaired(isOnline));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -246,7 +254,7 @@ class MailboxViewModel extends DbViewModel
|
||||
ioExecutor.execute(() -> {
|
||||
try {
|
||||
boolean wasWiped = mailboxManager.unPair();
|
||||
pairingState.postEvent(new MailboxState.WasUnpaired(!wasWiped));
|
||||
pairingState.postEvent(new WasUnpaired(!wasWiped));
|
||||
} catch (DbException e) {
|
||||
handleException(e);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ public class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
||||
private final ResultCallback callback;
|
||||
|
||||
private Camera camera = null;
|
||||
private int cameraIndex = 0;
|
||||
|
||||
public QrCodeDecoder(AndroidExecutor androidExecutor,
|
||||
@IoExecutor Executor ioExecutor, ResultCallback callback) {
|
||||
@@ -53,14 +52,12 @@ public class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
||||
@Override
|
||||
public void start(Camera camera, int cameraIndex) {
|
||||
this.camera = camera;
|
||||
this.cameraIndex = cameraIndex;
|
||||
askForPreviewFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
camera = null;
|
||||
cameraIndex = 0;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
||||
@@ -51,12 +51,12 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_xlarge"
|
||||
android:text="@string/add_contact_error_two_way"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
|
||||
app:layout_constraintBottom_toTopOf="@+id/sendFeedback"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/errorTitle"
|
||||
tools:text="error explanation" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/errorTitle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sendFeedback"
|
||||
|
||||
@@ -252,6 +252,8 @@
|
||||
<string name="qr_code_invalid">The QR code is invalid</string>
|
||||
<string name="qr_code_too_old_1">The QR code you have scanned comes from an older version of Briar.\n\nPlease ask your contact to upgrade to the latest version and then try again.</string>
|
||||
<string name="qr_code_too_new_1">The QR code you have scanned comes from a newer version of Briar.\n\nPlease upgrade to the latest version and then try again.</string>
|
||||
<string name="mailbox_qr_code_for_contact">The QR code you have scanned comes from Briar Mailbox.\n\nIf you want to link a Mailbox, please choose Settings > Mailbox from the Briar menu.</string>
|
||||
<string name="qr_code_format_unknown">The QR code you have scanned does not come from Briar.\n\nPlease scan the QR code shown on your contact\'s screen.</string>
|
||||
<string name="camera_error">Camera error</string>
|
||||
<string name="connecting_to_device">Connecting to device\u2026</string>
|
||||
<string name="authenticating_with_device">Authenticating with device\u2026</string>
|
||||
@@ -636,8 +638,10 @@
|
||||
<string name="mailbox_setup_connecting">Connecting to Mailbox…</string>
|
||||
<!-- This string is shown when connecting to a Mailbox for the first time. The placeholder will be replaced with a duration, e.g. "2 minutes". -->
|
||||
<string name="mailbox_setup_connecting_info">This may take up to %1s</string>
|
||||
<string name="mailbox_setup_qr_code_wrong_title">Wrong QR code</string>
|
||||
<string name="mailbox_setup_qr_code_wrong_description">The scanned code is invalid. Please open the Briar Mailbox app on your Mailbox device and scan the QR code it presents.</string>
|
||||
<string name="mailbox_qr_code_too_old">The QR code you have scanned comes from an older version of Briar Mailbox.\n\nPlease upgrade Briar Mailbox to the latest version and then try again.</string>
|
||||
<string name="mailbox_qr_code_too_new">The QR code you have scanned comes from a newer version of Briar Mailbox.\n\nPlease upgrade Briar to the latest version and then try again.</string>
|
||||
<string name="contact_qr_code_for_mailbox">The QR code you have scanned is for adding a Briar contact.\n\nIf you want to add a contact, please go to the contact list and tap the + icon.</string>
|
||||
<string name="mailbox_setup_qr_code_wrong_description">The QR code you have scanned does not come from Briar Mailbox.\n\nPlease open the Briar Mailbox app on your Mailbox device and scan the QR code it presents.</string>
|
||||
<string name="mailbox_setup_already_paired_title">Mailbox already linked</string>
|
||||
<string name="mailbox_setup_already_paired_description">Unlink the Mailbox on your other device and try again.</string>
|
||||
<string name="mailbox_setup_io_error_title">Could not connect</string>
|
||||
|
||||
Reference in New Issue
Block a user