mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Be less verbose
This commit is contained in:
@@ -46,7 +46,6 @@ import java.nio.channels.NotYetConnectedException;
|
||||
import java.security.PublicKey;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLException;
|
||||
import javax.net.ssl.SSLServerSocketFactory;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
@@ -66,7 +65,7 @@ public class LanLink extends BaseLink {
|
||||
@Override
|
||||
public void disconnect() {
|
||||
|
||||
Log.e("Disconnect","socket:"+ socket.hashCode());
|
||||
Log.i("LanLink/Disconnect","socket:"+ socket.hashCode());
|
||||
|
||||
if (socket == null) {
|
||||
Log.w("KDE/LanLink", "Not yet connected");
|
||||
@@ -101,35 +100,24 @@ public class LanLink extends BaseLink {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newSocket.getInputStream(), StringsHelper.UTF8));
|
||||
while (true) {
|
||||
if (socket.isClosed()) {
|
||||
Log.e("BufferReader", "Channel closed");
|
||||
break;
|
||||
}
|
||||
String packet;
|
||||
try {
|
||||
packet = reader.readLine();
|
||||
} catch (SocketTimeoutException e) {
|
||||
Log.w("BufferReader", "timeout");
|
||||
continue;
|
||||
}
|
||||
if (packet == null) {
|
||||
Log.w("BufferReader", "null package");
|
||||
break;
|
||||
}
|
||||
if (packet.isEmpty()) {
|
||||
Log.w("BufferReader", "empty package: " + packet);
|
||||
continue;
|
||||
throw new IOException("Read null");
|
||||
}
|
||||
if (packet.isEmpty()) continue;
|
||||
NetworkPackage np = NetworkPackage.unserialize(packet);
|
||||
injectNetworkPackage(np);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("LanLink", "Socket closed " + newSocket.hashCode() + " reason: " + e.getMessage());
|
||||
boolean thereIsaANewSocket = (newSocket != socket);
|
||||
linkProvider.socketClosed(newSocket, thereIsaANewSocket);
|
||||
}
|
||||
|
||||
Log.e("LanLink", "Socket closed"+newSocket.hashCode());
|
||||
boolean thereIsaANewSocket = (newSocket != socket);
|
||||
linkProvider.socketClosed(newSocket, thereIsaANewSocket);
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
@@ -114,20 +114,16 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
String message = reader.readLine();
|
||||
networkPackage = NetworkPackage.unserialize(message);
|
||||
Log.e("TcpListener","Received TCP package: "+networkPackage.serialize());
|
||||
//Log.i("TcpListener","Received TCP package: "+networkPackage.serialize());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (networkPackage.getType().equals(NetworkPackage.PACKAGE_TYPE_IDENTITY)) {
|
||||
|
||||
//TODO: Don't accept identity packet when already connected (move this if inside the check we do in the else)
|
||||
Log.i("KDE/LanLinkProvider", "Identity package received from a TCP connection from " + networkPackage.getString("deviceName"));
|
||||
identityPackageReceived(networkPackage, socket, LanLink.ConnectionStarted.Locally);
|
||||
|
||||
} else {
|
||||
|
||||
LanLink link = nioLinks.get(socket);
|
||||
if (link== null) {
|
||||
Log.e("KDE/LanLinkProvider","Expecting an identity package instead of " + networkPackage.getType());
|
||||
@@ -276,12 +272,6 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
|
||||
private void addLink(final NetworkPackage identityPackage, Socket socket, LanLink.ConnectionStarted connectionOrigin) throws IOException {
|
||||
|
||||
try {
|
||||
Log.e("addLink", identityPackage.serialize());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String deviceId = identityPackage.getString("deviceId");
|
||||
LanLink currentLink = visibleComputers.get(deviceId);
|
||||
if (currentLink != null) {
|
||||
@@ -298,7 +288,6 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
nioLinks.put(socket, currentLink);
|
||||
//Log.e("KDE/LanLinkProvider", "Replacing socket. old: "+ oldSocket.hashCode() + " - new: "+ socket.hashCode());
|
||||
} else {
|
||||
Log.e("addLink", "create link");
|
||||
//Let's create the link
|
||||
LanLink link = new LanLink(context, deviceId, this, socket, connectionOrigin);
|
||||
nioLinks.put(socket, link);
|
||||
@@ -349,9 +338,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
public void run() {
|
||||
while (running) {
|
||||
try {
|
||||
Log.e("ServerSocket","Waiting...");
|
||||
Socket socket = tcpServer.accept();
|
||||
Log.e("ServerSocket","Got a socket!");
|
||||
configureSocket(socket);
|
||||
tcpPackageReceived(socket);
|
||||
} catch (Exception e) {
|
||||
@@ -401,8 +388,8 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
try {
|
||||
InetAddress client = InetAddress.getByName(ipstr);
|
||||
socket.send(new DatagramPacket(bytes, bytes.length, client, port));
|
||||
//socket.send(new DatagramPacket(bytes, bytes.length, client, oldPort));
|
||||
Log.i("KDE/LanLinkProvider","Udp identity package sent to address "+client);
|
||||
socket.send(new DatagramPacket(bytes, bytes.length, client, oldPort));
|
||||
//Log.i("KDE/LanLinkProvider","Udp identity package sent to address "+client);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("KDE/LanLinkProvider", "Sending udp identity package failed. Invalid address? (" + ipstr + ")");
|
||||
|
Reference in New Issue
Block a user