2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 05:37:43 +00:00

Synchronize everything to see if this fixes a crash in 8.1

This commit is contained in:
Albert Vaca 2018-03-25 20:32:25 +02:00
parent 00b6677aa4
commit 3d4bf643d4

View File

@ -61,6 +61,9 @@ import javax.net.ssl.SSLSocket;
public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDisconnectedCallback {
public static final Object mutex = new Object();
public static final int MIN_VERSION_WITH_SSL_SUPPORT = 6;
public static final int MIN_VERSION_WITH_NEW_PORT_SUPPORT = 7;
@ -95,7 +98,10 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
NetworkPacket networkPacket;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String message = reader.readLine();
String message;
synchronized (mutex) {
message = reader.readLine();
}
networkPacket = NetworkPacket.unserialize(message);
//Log.e("TcpListener","Received TCP package: "+networkPacket.serialize());
} catch (Exception e) {
@ -143,9 +149,11 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
int tcpPort = identityPacket.getInt("tcpPort", MIN_PORT);
SocketFactory socketFactory = SocketFactory.getDefault();
Socket socket = socketFactory.createSocket(address, tcpPort);
configureSocket(socket);
Socket socket;
synchronized (mutex) {
socket = socketFactory.createSocket(address, tcpPort);
configureSocket(socket);
}
OutputStream out = socket.getOutputStream();
NetworkPacket myIdentity = NetworkPacket.createIdentityPacket(context);
out.write(myIdentity.serialize().getBytes());
@ -244,7 +252,9 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
@Override
public void run() {
try {
sslsocket.startHandshake();
synchronized (mutex) {
sslsocket.startHandshake();
}
} catch (Exception e) {
Log.e("KDE/LanLinkProvider","Handshake failed with " + identityPacket.getString("deviceName"));
e.printStackTrace();
@ -265,7 +275,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
}
private synchronized void addLink(final NetworkPacket identityPacket, Socket socket, LanLink.ConnectionStarted connectionOrigin) throws IOException {
private void addLink(final NetworkPacket identityPacket, Socket socket, LanLink.ConnectionStarted connectionOrigin) throws IOException {
String deviceId = identityPacket.getString("deviceId");
LanLink currentLink = visibleComputers.get(deviceId);
@ -328,8 +338,11 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
public void run() {
while (listening) {
try {
Socket socket = tcpServer.accept();
configureSocket(socket);
Socket socket;
synchronized (mutex) {
socket = tcpServer.accept();
configureSocket(socket);
}
tcpPacketReceived(socket);
} catch (Exception e) {
e.printStackTrace();