Let the limiter know whether connections closed cleanly.

This commit is contained in:
akwizgran
2020-05-06 14:59:36 +01:00
parent bda3b2100a
commit bd86ff2d5f
5 changed files with 12 additions and 9 deletions

View File

@@ -45,11 +45,13 @@ interface BluetoothConnectionLimiter {
/**
* Informs the limiter that the given connection has been closed.
*
* @param exception True if the connection was closed due to an exception.
*/
void connectionClosed(DuplexTransportConnection conn);
void connectionClosed(DuplexTransportConnection conn, boolean exception);
/**
* Informs the limiter that all connections have been closed.
* Informs the limiter that the Bluetooth adapter has been disabled.
*/
void allConnectionsClosed();
void bluetoothDisabled();
}

View File

@@ -126,7 +126,8 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
}
@Override
public void connectionClosed(DuplexTransportConnection conn) {
public void connectionClosed(DuplexTransportConnection conn,
boolean exception) {
synchronized (lock) {
Iterator<ConnectionRecord> it = connections.iterator();
while (it.hasNext()) {
@@ -141,10 +142,10 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
}
@Override
public void allConnectionsClosed() {
public void bluetoothDisabled() {
synchronized (lock) {
connections.clear();
LOG.info("All connections closed");
LOG.info("Bluetooth disabled");
}
}

View File

@@ -130,7 +130,7 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
void onAdapterDisabled() {
LOG.info("Bluetooth disabled");
tryToClose(socket);
connectionLimiter.allConnectionsClosed();
connectionLimiter.bluetoothDisabled();
callback.transportDisabled();
}