Compare commits

...

9 Commits

Author SHA1 Message Date
Michael Rogers
aafddcd0f0 Bumped version number for beta release (for real this time). 2017-08-01 16:43:47 +01:00
akwizgran
69bfb72171 Merge branch '1002-cam-get-params-npe' into 'master'
Catch RuntimeException when getting camera parameters

See merge request !579
2017-08-01 13:56:45 +00:00
Torsten Grote
1aa33ec9b2 Catch RuntimeException when getting camera parameters 2017-08-01 10:49:04 -03:00
akwizgran
6702df1e22 Merge branch '1008-qr-decoding-crash' into 'master'
Catch IllegalArgumentException when decoding QrCode

Closes #1008

See merge request !578
2017-08-01 13:36:09 +00:00
akwizgran
c1748c9a86 Bumped version number for beta release. 2017-08-01 14:32:05 +01:00
akwizgran
9df624c62a Merge branch '1009-camera-npe' into 'master'
Prevent NPE in CameraView

Closes #1009 and #997

See merge request !577
2017-08-01 13:29:33 +00:00
Torsten Grote
0ee6197d7f Catch IllegalArgumentException when decoding QrCode 2017-08-01 10:21:02 -03:00
Torsten Grote
b03a7dce3e Catch runtime exception when setting best camera parameters
Closes #997
2017-08-01 10:09:21 -03:00
Torsten Grote
6c59d7dd5f Prevent NPE in CameraView
This prevents crashes, but still might cause the camera to not show up
thus preventing the user from adding contacts.
2017-08-01 09:41:42 -03:00
4 changed files with 26 additions and 8 deletions

View File

@@ -78,8 +78,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
versionCode 1606
versionName "0.16.6"
versionCode 1608
versionName "0.16.8"
applicationId "org.briarproject.briar.beta"
resValue "string", "app_package", "org.briarproject.briar.beta"
buildConfigField "String", "GitHash", "\"${getGitHash()}\""

View File

@@ -7,6 +7,7 @@ import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.util.AttributeSet;
import android.view.Surface;
@@ -43,6 +44,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
private static final Logger LOG =
Logger.getLogger(CameraView.class.getName());
@Nullable
private Camera camera = null;
private PreviewConsumer previewConsumer = null;
private Surface surface = null;
@@ -86,6 +88,8 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
try {
LOG.info("Opening camera");
camera = Camera.open();
if (camera == null)
throw new RuntimeException("No back-facing camera.");
} catch (RuntimeException e) {
LOG.log(WARNING, "Error opening camera", e);
return;
@@ -129,6 +133,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
private void startPreview(SurfaceHolder holder) {
LOG.info("Starting preview");
try {
if (camera == null) throw new IOException("Camera is null.");
camera.setPreviewDisplay(holder);
camera.startPreview();
previewStarted = true;
@@ -142,6 +147,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
private void stopPreview() {
LOG.info("Stopping preview");
try {
if (camera == null) throw new RuntimeException("Camera is null.");
stopConsumer();
camera.stopPreview();
} catch (RuntimeException e) {
@@ -152,12 +158,14 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
@UiThread
private void startConsumer() {
if (camera == null) throw new RuntimeException("Camera is null");
if (autoFocus) camera.autoFocus(this);
previewConsumer.start(camera);
}
@UiThread
private void stopConsumer() {
if (camera == null) throw new RuntimeException("Camera is null");
if (autoFocus) camera.cancelAutoFocus();
previewConsumer.stop();
}
@@ -176,6 +184,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
if (LOG.isLoggable(INFO))
LOG.info("Display orientation " + orientation + " degrees");
try {
if (camera == null) throw new RuntimeException("Camera is null");
camera.setDisplayOrientation(orientation);
} catch (RuntimeException e) {
LOG.log(WARNING, "Error setting display orientation", e);
@@ -216,7 +225,11 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
setFocusMode(params);
params.setFlashMode(FLASH_MODE_OFF);
setPreviewSize(params);
camera.setParameters(params);
try {
camera.setParameters(params);
} catch (RuntimeException e) {
LOG.log(WARNING, "Error setting best camera parameters", e);
}
return camera.getParameters();
}
@@ -287,7 +300,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
@UiThread
private void logCameraParameters() {
if (LOG.isLoggable(INFO)) {
if (camera != null && LOG.isLoggable(INFO)) {
Parameters params = camera.getParameters();
if (Build.VERSION.SDK_INT >= 15) {
LOG.info("Video stabilisation enabled: "

View File

@@ -22,6 +22,7 @@ import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
@SuppressWarnings("deprecation")
@MethodsNotNullByDefault
@@ -60,8 +61,12 @@ class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
if (camera == this.camera) {
Size size = camera.getParameters().getPreviewSize();
new DecoderTask(data, size.width, size.height).execute();
try {
Size size = camera.getParameters().getPreviewSize();
new DecoderTask(data, size.width, size.height).execute();
} catch (RuntimeException e) {
LOG.log(WARNING, "Error getting camera parameters.", e);
}
}
}
@@ -70,7 +75,7 @@ class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
private final byte[] data;
private final int width, height;
DecoderTask(byte[] data, int width, int height) {
private DecoderTask(byte[] data, int width, int height) {
this.data = data;
this.width = width;
this.height = height;

View File

@@ -218,7 +218,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
statusView.setVisibility(VISIBLE);
status.setText(R.string.connecting_to_device);
task.connectAndRunProtocol(remotePayload);
} catch (IOException e) {
} catch (IOException | IllegalArgumentException e) {
// TODO show failure
Toast.makeText(getActivity(), R.string.qr_code_invalid,
LENGTH_LONG).show();