mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Merge branch '2005-connect-via-bt-error' into 'master'
Connect via Bluetooth: Wait before showing an error Toast See merge request briar/briar!1446
This commit is contained in:
@@ -221,15 +221,12 @@ class BluetoothConnecter implements EventListener {
|
|||||||
DuplexTransportConnection conn = bluetoothPlugin
|
DuplexTransportConnection conn = bluetoothPlugin
|
||||||
.discoverAndConnectForSetup(uuid);
|
.discoverAndConnectForSetup(uuid);
|
||||||
if (conn == null) {
|
if (conn == null) {
|
||||||
if (!isConnectedViaBluetooth(contactId)) {
|
waitAfterConnectionFailed();
|
||||||
LOG.warning("Failed to connect");
|
} else {
|
||||||
showToast(
|
LOG.info("Could connect, handling connection");
|
||||||
R.string.toast_connect_via_bluetooth_error);
|
connectionManager
|
||||||
} else {
|
.manageOutgoingConnection(contactId, ID, conn);
|
||||||
LOG.info(
|
showToast(R.string.toast_connect_via_bluetooth_success);
|
||||||
"Failed to connect, but contact connected");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
connectionManager
|
connectionManager
|
||||||
.manageOutgoingConnection(contactId, ID, conn);
|
.manageOutgoingConnection(contactId, ID, conn);
|
||||||
@@ -243,6 +240,7 @@ class BluetoothConnecter implements EventListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IoExecutor
|
||||||
private boolean waitForBluetoothActive() {
|
private boolean waitForBluetoothActive() {
|
||||||
long left = BT_ACTIVE_TIMEOUT;
|
long left = BT_ACTIVE_TIMEOUT;
|
||||||
final long sleep = 250;
|
final long sleep = 250;
|
||||||
@@ -260,6 +258,31 @@ class BluetoothConnecter implements EventListener {
|
|||||||
return (bluetoothPlugin.getState() == ACTIVE);
|
return (bluetoothPlugin.getState() == ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait for an incoming connection before showing an error Toast.
|
||||||
|
*/
|
||||||
|
@IoExecutor
|
||||||
|
private void waitAfterConnectionFailed() {
|
||||||
|
long left = BT_ACTIVE_TIMEOUT;
|
||||||
|
final long sleep = 250;
|
||||||
|
try {
|
||||||
|
while (left > 0) {
|
||||||
|
if (isConnectedViaBluetooth(contactId)) {
|
||||||
|
LOG.info("Failed to connect, but contact connected");
|
||||||
|
// no Toast needed here, as it gets shown when
|
||||||
|
// ConnectionOpenedEvent is received
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Thread.sleep(sleep);
|
||||||
|
left -= sleep;
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
LOG.warning("Failed to connect");
|
||||||
|
showToast(R.string.toast_connect_via_bluetooth_error);
|
||||||
|
}
|
||||||
|
|
||||||
private void showToast(@StringRes int res) {
|
private void showToast(@StringRes int res) {
|
||||||
androidExecutor.runOnUiThread(() ->
|
androidExecutor.runOnUiThread(() ->
|
||||||
Toast.makeText(app, res, Toast.LENGTH_LONG).show()
|
Toast.makeText(app, res, Toast.LENGTH_LONG).show()
|
||||||
|
|||||||
Reference in New Issue
Block a user