mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
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:
@@ -225,6 +225,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
||||
protected void onPostExecute(Camera camera) {
|
||||
if (camera == null) {
|
||||
// TODO better solution?
|
||||
LOG.info("No Camera found, finishing...");
|
||||
getActivity().finish();
|
||||
} else {
|
||||
cameraView.start(camera, decoder, 0);
|
||||
|
||||
@@ -86,6 +86,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
||||
public void stop() {
|
||||
stopPreview();
|
||||
try {
|
||||
if (camera != null)
|
||||
camera.release();
|
||||
} catch (RuntimeException e) {
|
||||
LOG.log(WARNING, "Error releasing camera", e);
|
||||
@@ -106,6 +107,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
||||
private void stopPreview() {
|
||||
try {
|
||||
stopConsumer();
|
||||
if (camera != null)
|
||||
camera.stopPreview();
|
||||
} catch (RuntimeException e) {
|
||||
LOG.log(WARNING, "Error stopping camera preview", e);
|
||||
@@ -118,7 +120,9 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
||||
}
|
||||
|
||||
public void stopConsumer() {
|
||||
if (previewConsumer != null) {
|
||||
previewConsumer.stop();
|
||||
}
|
||||
if (autoFocus) camera.cancelAutoFocus();
|
||||
}
|
||||
|
||||
|
||||
@@ -261,7 +261,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return running && adapter.isEnabled();
|
||||
return running && adapter != null && adapter.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -446,6 +446,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
@Override
|
||||
public KeyAgreementListener createKeyAgreementListener(byte[] commitment) {
|
||||
if (!isRunning()) return null;
|
||||
// No truncation necessary because COMMIT_LENGTH = 16
|
||||
UUID uuid = UUID.nameUUIDFromBytes(commitment);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Key agreement UUID " + uuid);
|
||||
@@ -616,7 +617,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
private final BluetoothServerSocket ss;
|
||||
|
||||
public BluetoothKeyAgreementListener(TransportDescriptor descriptor,
|
||||
BluetoothKeyAgreementListener(TransportDescriptor descriptor,
|
||||
BluetoothServerSocket ss) {
|
||||
super(descriptor);
|
||||
this.ss = ss;
|
||||
|
||||
@@ -51,7 +51,7 @@ class KeyAgreementConnector {
|
||||
private volatile boolean connecting = false;
|
||||
private volatile boolean alice = false;
|
||||
|
||||
public KeyAgreementConnector(Callbacks callbacks, Clock clock,
|
||||
KeyAgreementConnector(Callbacks callbacks, Clock clock,
|
||||
CryptoComponent crypto, PluginManager pluginManager,
|
||||
Executor ioExecutor) {
|
||||
this.callbacks = callbacks;
|
||||
@@ -83,7 +83,7 @@ class KeyAgreementConnector {
|
||||
return new Payload(commitment, descriptors);
|
||||
}
|
||||
|
||||
public void stopListening() {
|
||||
void stopListening() {
|
||||
LOG.info("Stopping BQP listeners");
|
||||
for (KeyAgreementListener l : listeners) {
|
||||
l.close();
|
||||
|
||||
@@ -363,6 +363,7 @@ class BluetoothPlugin implements DuplexPlugin {
|
||||
|
||||
@Override
|
||||
public KeyAgreementListener createKeyAgreementListener(byte[] commitment) {
|
||||
if (!running) return null;
|
||||
// No truncation necessary because COMMIT_LENGTH = 16
|
||||
String uuid = UUID.nameUUIDFromBytes(commitment).toString();
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Key agreement UUID " + uuid);
|
||||
@@ -490,7 +491,7 @@ class BluetoothPlugin implements DuplexPlugin {
|
||||
|
||||
private final StreamConnectionNotifier ss;
|
||||
|
||||
public BluetoothKeyAgreementListener(TransportDescriptor descriptor,
|
||||
BluetoothKeyAgreementListener(TransportDescriptor descriptor,
|
||||
StreamConnectionNotifier ss) {
|
||||
super(descriptor);
|
||||
this.ss = ss;
|
||||
|
||||
Reference in New Issue
Block a user