From 0b89d29c7d52c6fd0053931aabd3ff2c40b84e59 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 20 Apr 2021 12:13:07 -0300 Subject: [PATCH] Reset BluetoothPlugin reference When it is assigned before we are signed-in in (like when returning to a killed activity), it would be null and without a reset, we would consider Bluetooth to not be supported. --- .../android/conversation/BluetoothConnecter.java | 14 +++++++++----- .../BluetoothConnecterDialogFragment.java | 3 +-- 2 files changed, 10 insertions(+), 7 deletions(-) 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