From 53f85d4b7172c49e3c3d4f54327016791f3c35ad Mon Sep 17 00:00:00 2001 From: akwizgran Date: Tue, 20 Mar 2018 11:58:40 +0000 Subject: [PATCH] When resetting, restart camera if we've stopped it. --- .../keyagreement/ShowQrCodeFragment.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/ShowQrCodeFragment.java b/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/ShowQrCodeFragment.java index 6e5fe688b..9608385aa 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/ShowQrCodeFragment.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/ShowQrCodeFragment.java @@ -205,6 +205,15 @@ public class ShowQrCodeFragment extends BaseEventFragment @UiThread private void reset() { + // If we've stopped the camera view, restart it + if (gotRemotePayload) { + try { + cameraView.start(getScreenRotationDegrees()); + } catch (CameraException e) { + logCameraExceptionAndFinish(e); + return; + } + } statusView.setVisibility(INVISIBLE); cameraView.setVisibility(VISIBLE); gotRemotePayload = false; @@ -219,12 +228,17 @@ public class ShowQrCodeFragment extends BaseEventFragment if (LOG.isLoggable(INFO)) LOG.info("Remote payload is " + encoded.length + " bytes"); Payload remotePayload = payloadParser.parse(encoded); + gotRemotePayload = true; + cameraView.stop(); cameraView.setVisibility(INVISIBLE); statusView.setVisibility(VISIBLE); status.setText(R.string.connecting_to_device); task.connectAndRunProtocol(remotePayload); + } catch (CameraException e) { + logCameraExceptionAndFinish(e); } catch (IOException | IllegalArgumentException e) { - // TODO show failure + if (LOG.isLoggable(WARNING)) LOG.log(WARNING, "QR Code Invalid", e); + reset(); Toast.makeText(getActivity(), R.string.qr_code_invalid, LENGTH_LONG).show(); } @@ -262,6 +276,7 @@ public class ShowQrCodeFragment extends BaseEventFragment new AsyncTask() { @Override + @Nullable protected Bitmap doInBackground(Void... params) { byte[] encoded = payloadEncoder.encode(payload); if (LOG.isLoggable(INFO)) @@ -326,13 +341,8 @@ public class ShowQrCodeFragment extends BaseEventFragment runOnUiThreadUnlessDestroyed(() -> { LOG.info("Got result from decoder"); // Ignore results until the KeyAgreementTask is ready - if (!gotLocalPayload) { - return; - } - if (!gotRemotePayload) { - gotRemotePayload = true; - qrCodeScanned(result.getText()); - } + if (!gotLocalPayload) return; + if (!gotRemotePayload) qrCodeScanned(result.getText()); }); }