Check if Bluetooth is supported before requesting discoverability

This commit is contained in:
Torsten Grote
2021-04-01 15:34:21 -03:00
parent 4f3e4b019a
commit 5b52417d20
2 changed files with 12 additions and 11 deletions

View File

@@ -143,17 +143,13 @@ public class AddNearbyContactActivity extends BriarActivity
}
private void requestBluetoothDiscoverable() {
if (!viewModel.isBluetoothSupported()) {
viewModel.setBluetoothDecision(BluetoothDecision.NO_ADAPTER);
Intent i = new Intent(ACTION_REQUEST_DISCOVERABLE);
if (i.resolveActivity(getPackageManager()) != null) {
LOG.info("Asking for Bluetooth discoverability");
viewModel.setBluetoothDecision(BluetoothDecision.WAITING);
bluetoothLauncher.launch(120); // 2min discoverable
} else {
Intent i = new Intent(ACTION_REQUEST_DISCOVERABLE);
if (i.resolveActivity(getPackageManager()) != null) {
LOG.info("Asking for Bluetooth discoverability");
viewModel.setBluetoothDecision(BluetoothDecision.WAITING);
bluetoothLauncher.launch(120); // 2min discoverable
} else {
viewModel.setBluetoothDecision(BluetoothDecision.NO_ADAPTER);
}
viewModel.setBluetoothDecision(BluetoothDecision.NO_ADAPTER);
}
}

View File

@@ -84,6 +84,7 @@ import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactPermissionManager.areEssentialPermissionsGranted;
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactPermissionManager.isLocationEnabled;
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactViewModel.BluetoothDecision.NO_ADAPTER;
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactViewModel.BluetoothDecision.REFUSED;
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactViewModel.BluetoothDecision.UNKNOWN;
@@ -375,7 +376,11 @@ class AddNearbyContactViewModel extends AndroidViewModel
} else {
enableWifiIfWeShould();
if (bluetoothDecision == UNKNOWN) {
requestBluetoothDiscoverable.setEvent(true);
if (isBluetoothSupported()) {
requestBluetoothDiscoverable.setEvent(true);
} else {
bluetoothDecision = NO_ADAPTER;
}
} else if (bluetoothDecision == REFUSED) {
// Ask again when the user clicks "continue"
} else {