Fix crashes when no Bluetooth or no Camera is available

Briar crashed when run in a device without bluetooth or without camera
such as an emulator.

Closes #514
This commit is contained in:
Torsten Grote
2016-08-04 16:44:28 -03:00
parent 054a0d467c
commit b04bde4f41
5 changed files with 15 additions and 8 deletions

View File

@@ -225,6 +225,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
protected void onPostExecute(Camera camera) { protected void onPostExecute(Camera camera) {
if (camera == null) { if (camera == null) {
// TODO better solution? // TODO better solution?
LOG.info("No Camera found, finishing...");
getActivity().finish(); getActivity().finish();
} else { } else {
cameraView.start(camera, decoder, 0); cameraView.start(camera, decoder, 0);

View File

@@ -86,7 +86,8 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
public void stop() { public void stop() {
stopPreview(); stopPreview();
try { try {
camera.release(); if (camera != null)
camera.release();
} catch (RuntimeException e) { } catch (RuntimeException e) {
LOG.log(WARNING, "Error releasing camera", e); LOG.log(WARNING, "Error releasing camera", e);
} }
@@ -106,7 +107,8 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
private void stopPreview() { private void stopPreview() {
try { try {
stopConsumer(); stopConsumer();
camera.stopPreview(); if (camera != null)
camera.stopPreview();
} catch (RuntimeException e) { } catch (RuntimeException e) {
LOG.log(WARNING, "Error stopping camera preview", e); LOG.log(WARNING, "Error stopping camera preview", e);
} }
@@ -118,7 +120,9 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
} }
public void stopConsumer() { public void stopConsumer() {
previewConsumer.stop(); if (previewConsumer != null) {
previewConsumer.stop();
}
if (autoFocus) camera.cancelAutoFocus(); if (autoFocus) camera.cancelAutoFocus();
} }

View File

@@ -261,7 +261,7 @@ class DroidtoothPlugin implements DuplexPlugin {
@Override @Override
public boolean isRunning() { public boolean isRunning() {
return running && adapter.isEnabled(); return running && adapter != null && adapter.isEnabled();
} }
@Override @Override
@@ -446,6 +446,7 @@ class DroidtoothPlugin implements DuplexPlugin {
@Override @Override
public KeyAgreementListener createKeyAgreementListener(byte[] commitment) { public KeyAgreementListener createKeyAgreementListener(byte[] commitment) {
if (!isRunning()) return null;
// No truncation necessary because COMMIT_LENGTH = 16 // No truncation necessary because COMMIT_LENGTH = 16
UUID uuid = UUID.nameUUIDFromBytes(commitment); UUID uuid = UUID.nameUUIDFromBytes(commitment);
if (LOG.isLoggable(INFO)) LOG.info("Key agreement UUID " + uuid); if (LOG.isLoggable(INFO)) LOG.info("Key agreement UUID " + uuid);
@@ -616,7 +617,7 @@ class DroidtoothPlugin implements DuplexPlugin {
private final BluetoothServerSocket ss; private final BluetoothServerSocket ss;
public BluetoothKeyAgreementListener(TransportDescriptor descriptor, BluetoothKeyAgreementListener(TransportDescriptor descriptor,
BluetoothServerSocket ss) { BluetoothServerSocket ss) {
super(descriptor); super(descriptor);
this.ss = ss; this.ss = ss;

View File

@@ -51,7 +51,7 @@ class KeyAgreementConnector {
private volatile boolean connecting = false; private volatile boolean connecting = false;
private volatile boolean alice = false; private volatile boolean alice = false;
public KeyAgreementConnector(Callbacks callbacks, Clock clock, KeyAgreementConnector(Callbacks callbacks, Clock clock,
CryptoComponent crypto, PluginManager pluginManager, CryptoComponent crypto, PluginManager pluginManager,
Executor ioExecutor) { Executor ioExecutor) {
this.callbacks = callbacks; this.callbacks = callbacks;
@@ -83,7 +83,7 @@ class KeyAgreementConnector {
return new Payload(commitment, descriptors); return new Payload(commitment, descriptors);
} }
public void stopListening() { void stopListening() {
LOG.info("Stopping BQP listeners"); LOG.info("Stopping BQP listeners");
for (KeyAgreementListener l : listeners) { for (KeyAgreementListener l : listeners) {
l.close(); l.close();

View File

@@ -363,6 +363,7 @@ class BluetoothPlugin implements DuplexPlugin {
@Override @Override
public KeyAgreementListener createKeyAgreementListener(byte[] commitment) { public KeyAgreementListener createKeyAgreementListener(byte[] commitment) {
if (!running) return null;
// No truncation necessary because COMMIT_LENGTH = 16 // No truncation necessary because COMMIT_LENGTH = 16
String uuid = UUID.nameUUIDFromBytes(commitment).toString(); String uuid = UUID.nameUUIDFromBytes(commitment).toString();
if (LOG.isLoggable(INFO)) LOG.info("Key agreement UUID " + uuid); if (LOG.isLoggable(INFO)) LOG.info("Key agreement UUID " + uuid);
@@ -490,7 +491,7 @@ class BluetoothPlugin implements DuplexPlugin {
private final StreamConnectionNotifier ss; private final StreamConnectionNotifier ss;
public BluetoothKeyAgreementListener(TransportDescriptor descriptor, BluetoothKeyAgreementListener(TransportDescriptor descriptor,
StreamConnectionNotifier ss) { StreamConnectionNotifier ss) {
super(descriptor); super(descriptor);
this.ss = ss; this.ss = ss;