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.
This commit is contained in:
Torsten Grote
2021-04-20 12:13:07 -03:00
parent 688bac77a8
commit 0b89d29c7d
2 changed files with 10 additions and 7 deletions

View File

@@ -47,11 +47,13 @@ class BluetoothConnecter {
} }
private final Application app; private final Application app;
private final PluginManager pluginManager;
private final Executor ioExecutor; private final Executor ioExecutor;
private final AndroidExecutor androidExecutor; private final AndroidExecutor androidExecutor;
private final ConnectionRegistry connectionRegistry; private final ConnectionRegistry connectionRegistry;
private final BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter(); private final BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
private final Plugin bluetoothPlugin;
private volatile Plugin bluetoothPlugin;
private Permission locationPermission = Permission.UNKNOWN; private Permission locationPermission = Permission.UNKNOWN;
@@ -62,6 +64,7 @@ class BluetoothConnecter {
AndroidExecutor androidExecutor, AndroidExecutor androidExecutor,
ConnectionRegistry connectionRegistry) { ConnectionRegistry connectionRegistry) {
this.app = app; this.app = app;
this.pluginManager = pluginManager;
this.ioExecutor = ioExecutor; this.ioExecutor = ioExecutor;
this.androidExecutor = androidExecutor; this.androidExecutor = androidExecutor;
this.bluetoothPlugin = pluginManager.getPlugin(BluetoothConstants.ID); this.bluetoothPlugin = pluginManager.getPlugin(BluetoothConstants.ID);
@@ -81,8 +84,12 @@ class BluetoothConnecter {
* Call this when the using activity or fragment starts, * Call this when the using activity or fragment starts,
* because permissions might have changed while it was stopped. * because permissions might have changed while it was stopped.
*/ */
void resetPermissions() { void reset() {
locationPermission = Permission.UNKNOWN; 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 @UiThread
@@ -99,9 +106,6 @@ class BluetoothConnecter {
} }
boolean isBluetoothNotSupported() { 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; return bt == null || bluetoothPlugin == null;
} }

View File

@@ -75,6 +75,7 @@ public class BluetoothConnecterDialogFragment extends DialogFragment {
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
bluetoothConnecter.reset();
if (bluetoothConnecter.isBluetoothNotSupported()) { if (bluetoothConnecter.isBluetoothNotSupported()) {
showToast(R.string.toast_connect_via_bluetooth_error); showToast(R.string.toast_connect_via_bluetooth_error);
dismiss(); dismiss();
@@ -92,9 +93,7 @@ public class BluetoothConnecterDialogFragment extends DialogFragment {
if (bluetoothConnecter.isDiscovering()) { if (bluetoothConnecter.isDiscovering()) {
// TODO showToast(R.string.toast_connect_via_bluetooth_discovering); // TODO showToast(R.string.toast_connect_via_bluetooth_discovering);
dismiss(); dismiss();
return;
} }
bluetoothConnecter.resetPermissions();
} }
@Override @Override