mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 07:09:56 +01:00
Merge branch 'raw-qr-codes' into 'master'
Use raw byte mode for QR codes See merge request akwizgran/briar!696
This commit is contained in:
@@ -21,6 +21,8 @@ import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static com.google.zxing.DecodeHintType.CHARACTER_SET;
|
||||||
|
import static java.util.Collections.singletonMap;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
|
|
||||||
@@ -87,9 +89,10 @@ class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
|||||||
LuminanceSource src = new PlanarYUVLuminanceSource(data, width,
|
LuminanceSource src = new PlanarYUVLuminanceSource(data, width,
|
||||||
height, 0, 0, width, height, false);
|
height, 0, 0, width, height, false);
|
||||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(src));
|
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(src));
|
||||||
Result result = null;
|
Result result;
|
||||||
try {
|
try {
|
||||||
result = reader.decode(bitmap);
|
result = reader.decode(bitmap,
|
||||||
|
singletonMap(CHARACTER_SET, "ISO8859_1"));
|
||||||
} catch (ReaderException e) {
|
} catch (ReaderException e) {
|
||||||
return null; // No barcode found
|
return null; // No barcode found
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import android.graphics.Bitmap;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
import android.util.Base64;
|
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -37,6 +36,7 @@ import org.briarproject.briar.android.activity.ActivityComponent;
|
|||||||
import org.briarproject.briar.android.fragment.BaseEventFragment;
|
import org.briarproject.briar.android.fragment.BaseEventFragment;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -58,6 +58,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
|||||||
|
|
||||||
private static final String TAG = ShowQrCodeFragment.class.getName();
|
private static final String TAG = ShowQrCodeFragment.class.getName();
|
||||||
private static final Logger LOG = Logger.getLogger(TAG);
|
private static final Logger LOG = Logger.getLogger(TAG);
|
||||||
|
private static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Provider<KeyAgreementTask> keyAgreementTaskProvider;
|
Provider<KeyAgreementTask> keyAgreementTaskProvider;
|
||||||
@@ -192,10 +193,11 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
|||||||
@UiThread
|
@UiThread
|
||||||
private void qrCodeScanned(String content) {
|
private void qrCodeScanned(String content) {
|
||||||
try {
|
try {
|
||||||
byte[] encoded = Base64.decode(content, 0);
|
byte[] payloadBytes = content.getBytes(ISO_8859_1);
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Remote payload is " + encoded.length + " bytes");
|
LOG.info("Remote payload is " + payloadBytes.length + " bytes");
|
||||||
Payload remotePayload = payloadParser.parse(encoded);
|
Payload remotePayload = payloadParser.parse(payloadBytes);
|
||||||
|
gotRemotePayload = true;
|
||||||
cameraView.setVisibility(INVISIBLE);
|
cameraView.setVisibility(INVISIBLE);
|
||||||
statusView.setVisibility(VISIBLE);
|
statusView.setVisibility(VISIBLE);
|
||||||
status.setText(R.string.connecting_to_device);
|
status.setText(R.string.connecting_to_device);
|
||||||
@@ -240,11 +242,14 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Bitmap doInBackground(Void... params) {
|
protected Bitmap doInBackground(Void... params) {
|
||||||
byte[] encoded = payloadEncoder.encode(payload);
|
byte[] payloadBytes = payloadEncoder.encode(payload);
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO)) {
|
||||||
LOG.info("Local payload is " + encoded.length + " bytes");
|
LOG.info("Local payload is " + payloadBytes.length
|
||||||
String input = Base64.encodeToString(encoded, 0);
|
+ " bytes");
|
||||||
return QrCodeUtils.createQrCode(dm, input);
|
}
|
||||||
|
// Use ISO 8859-1 to encode bytes directly as a string
|
||||||
|
String content = new String(payloadBytes, ISO_8859_1);
|
||||||
|
return QrCodeUtils.createQrCode(dm, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -303,13 +308,8 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
|||||||
runOnUiThreadUnlessDestroyed(() -> {
|
runOnUiThreadUnlessDestroyed(() -> {
|
||||||
LOG.info("Got result from decoder");
|
LOG.info("Got result from decoder");
|
||||||
// Ignore results until the KeyAgreementTask is ready
|
// Ignore results until the KeyAgreementTask is ready
|
||||||
if (!gotLocalPayload) {
|
if (!gotLocalPayload) return;
|
||||||
return;
|
if (!gotRemotePayload) qrCodeScanned(result.getText());
|
||||||
}
|
|
||||||
if (!gotRemotePayload) {
|
|
||||||
gotRemotePayload = true;
|
|
||||||
qrCodeScanned(result.getText());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user