diff --git a/briar-android/src/main/java/org/briarproject/briar/android/conversation/BluetoothConnecter.java b/briar-android/src/main/java/org/briarproject/briar/android/conversation/BluetoothConnecter.java index c3a04d4d2..452e7fd78 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/conversation/BluetoothConnecter.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/conversation/BluetoothConnecter.java @@ -47,11 +47,13 @@ class BluetoothConnecter { } private final Application app; + private final PluginManager pluginManager; private final Executor ioExecutor; private final AndroidExecutor androidExecutor; private final ConnectionRegistry connectionRegistry; private final BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter(); - private final Plugin bluetoothPlugin; + + private volatile Plugin bluetoothPlugin; private Permission locationPermission = Permission.UNKNOWN; @@ -62,6 +64,7 @@ class BluetoothConnecter { AndroidExecutor androidExecutor, ConnectionRegistry connectionRegistry) { this.app = app; + this.pluginManager = pluginManager; this.ioExecutor = ioExecutor; this.androidExecutor = androidExecutor; this.bluetoothPlugin = pluginManager.getPlugin(BluetoothConstants.ID); @@ -81,8 +84,12 @@ class BluetoothConnecter { * Call this when the using activity or fragment starts, * because permissions might have changed while it was stopped. */ - void resetPermissions() { + void reset() { locationPermission = Permission.UNKNOWN; + // When this class is instantiated before we are logged in + // (like when returning to a killed activity), bluetoothPlugin would be + // null and we consider bluetooth not supported. So reset here. + bluetoothPlugin = pluginManager.getPlugin(BluetoothConstants.ID); } @UiThread @@ -99,9 +106,6 @@ class BluetoothConnecter { } boolean isBluetoothNotSupported() { - // When this class is instantiated before we are logged in - // (like when returning to a killed activity), bluetoothPlugin will be - // null and we consider bluetooth not supported. return bt == null || bluetoothPlugin == null; } diff --git a/briar-android/src/main/java/org/briarproject/briar/android/conversation/BluetoothConnecterDialogFragment.java b/briar-android/src/main/java/org/briarproject/briar/android/conversation/BluetoothConnecterDialogFragment.java index 46f0f9b4a..bb2d5ff82 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/conversation/BluetoothConnecterDialogFragment.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/conversation/BluetoothConnecterDialogFragment.java @@ -75,6 +75,7 @@ public class BluetoothConnecterDialogFragment extends DialogFragment { @Override public void onStart() { super.onStart(); + bluetoothConnecter.reset(); if (bluetoothConnecter.isBluetoothNotSupported()) { showToast(R.string.toast_connect_via_bluetooth_error); dismiss(); @@ -92,9 +93,7 @@ public class BluetoothConnecterDialogFragment extends DialogFragment { if (bluetoothConnecter.isDiscovering()) { // TODO showToast(R.string.toast_connect_via_bluetooth_discovering); dismiss(); - return; } - bluetoothConnecter.resetPermissions(); } @Override