mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 13:47:41 +00:00
Synchronize everything to see if this fixes a crash in 8.1
This commit is contained in:
parent
00b6677aa4
commit
3d4bf643d4
@ -61,6 +61,9 @@ import javax.net.ssl.SSLSocket;
|
|||||||
|
|
||||||
public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDisconnectedCallback {
|
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_SSL_SUPPORT = 6;
|
||||||
public static final int MIN_VERSION_WITH_NEW_PORT_SUPPORT = 7;
|
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;
|
NetworkPacket networkPacket;
|
||||||
try {
|
try {
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
String message = reader.readLine();
|
String message;
|
||||||
|
synchronized (mutex) {
|
||||||
|
message = reader.readLine();
|
||||||
|
}
|
||||||
networkPacket = NetworkPacket.unserialize(message);
|
networkPacket = NetworkPacket.unserialize(message);
|
||||||
//Log.e("TcpListener","Received TCP package: "+networkPacket.serialize());
|
//Log.e("TcpListener","Received TCP package: "+networkPacket.serialize());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -143,9 +149,11 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
int tcpPort = identityPacket.getInt("tcpPort", MIN_PORT);
|
int tcpPort = identityPacket.getInt("tcpPort", MIN_PORT);
|
||||||
|
|
||||||
SocketFactory socketFactory = SocketFactory.getDefault();
|
SocketFactory socketFactory = SocketFactory.getDefault();
|
||||||
Socket socket = socketFactory.createSocket(address, tcpPort);
|
Socket socket;
|
||||||
configureSocket(socket);
|
synchronized (mutex) {
|
||||||
|
socket = socketFactory.createSocket(address, tcpPort);
|
||||||
|
configureSocket(socket);
|
||||||
|
}
|
||||||
OutputStream out = socket.getOutputStream();
|
OutputStream out = socket.getOutputStream();
|
||||||
NetworkPacket myIdentity = NetworkPacket.createIdentityPacket(context);
|
NetworkPacket myIdentity = NetworkPacket.createIdentityPacket(context);
|
||||||
out.write(myIdentity.serialize().getBytes());
|
out.write(myIdentity.serialize().getBytes());
|
||||||
@ -244,7 +252,9 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
sslsocket.startHandshake();
|
synchronized (mutex) {
|
||||||
|
sslsocket.startHandshake();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e("KDE/LanLinkProvider","Handshake failed with " + identityPacket.getString("deviceName"));
|
Log.e("KDE/LanLinkProvider","Handshake failed with " + identityPacket.getString("deviceName"));
|
||||||
e.printStackTrace();
|
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");
|
String deviceId = identityPacket.getString("deviceId");
|
||||||
LanLink currentLink = visibleComputers.get(deviceId);
|
LanLink currentLink = visibleComputers.get(deviceId);
|
||||||
@ -328,8 +338,11 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
public void run() {
|
public void run() {
|
||||||
while (listening) {
|
while (listening) {
|
||||||
try {
|
try {
|
||||||
Socket socket = tcpServer.accept();
|
Socket socket;
|
||||||
configureSocket(socket);
|
synchronized (mutex) {
|
||||||
|
socket = tcpServer.accept();
|
||||||
|
configureSocket(socket);
|
||||||
|
}
|
||||||
tcpPacketReceived(socket);
|
tcpPacketReceived(socket);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user