mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Ensure server socket is closed.
This commit is contained in:
@@ -32,9 +32,11 @@ import static android.net.ConnectivityManager.TYPE_WIFI;
|
|||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||||
import static org.briarproject.bramble.api.plugin.Plugin.State.INACTIVE;
|
import static org.briarproject.bramble.api.plugin.Plugin.State.INACTIVE;
|
||||||
|
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class AndroidLanTcpPlugin extends LanTcpPlugin implements EventListener {
|
class AndroidLanTcpPlugin extends LanTcpPlugin implements EventListener {
|
||||||
@@ -132,8 +134,8 @@ class AndroidLanTcpPlugin extends LanTcpPlugin implements EventListener {
|
|||||||
|
|
||||||
private void updateConnectionStatus() {
|
private void updateConnectionStatus() {
|
||||||
connectionStatusExecutor.execute(() -> {
|
connectionStatusExecutor.execute(() -> {
|
||||||
State state = getState();
|
State s = getState();
|
||||||
if (state != ACTIVE && state != INACTIVE) return;
|
if (s != ACTIVE && s != INACTIVE) return;
|
||||||
List<InetAddress> addrs = getLocalInetAddresses();
|
List<InetAddress> addrs = getLocalInetAddresses();
|
||||||
if (addrs.contains(WIFI_AP_ADDRESS)
|
if (addrs.contains(WIFI_AP_ADDRESS)
|
||||||
|| addrs.contains(WIFI_DIRECT_AP_ADDRESS)) {
|
|| addrs.contains(WIFI_DIRECT_AP_ADDRESS)) {
|
||||||
@@ -143,15 +145,21 @@ class AndroidLanTcpPlugin extends LanTcpPlugin implements EventListener {
|
|||||||
// make outgoing connections on API 21+ if another network
|
// make outgoing connections on API 21+ if another network
|
||||||
// has internet access
|
// has internet access
|
||||||
socketFactory = SocketFactory.getDefault();
|
socketFactory = SocketFactory.getDefault();
|
||||||
if (state == INACTIVE) bind();
|
if (s == INACTIVE) bind();
|
||||||
} else if (addrs.isEmpty()) {
|
} else if (addrs.isEmpty()) {
|
||||||
LOG.info("Not connected to wifi");
|
LOG.info("Not connected to wifi");
|
||||||
socketFactory = SocketFactory.getDefault();
|
socketFactory = SocketFactory.getDefault();
|
||||||
// Server socket was closed when wifi interface went down
|
// Server socket may not have been closed automatically when
|
||||||
|
// interface was taken down. Socket will be cleared and state
|
||||||
|
// updated in acceptContactConnections()
|
||||||
|
if (s == ACTIVE) {
|
||||||
|
LOG.info("Closing server socket");
|
||||||
|
tryToClose(state.getServerSocket(), LOG, WARNING);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Connected to wifi");
|
LOG.info("Connected to wifi");
|
||||||
socketFactory = getSocketFactory();
|
socketFactory = getSocketFactory();
|
||||||
if (state == INACTIVE) bind();
|
if (s == INACTIVE) bind();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user