diff --git a/src/org/kde/kdeconnect/Backends/BaseLinkProvider.java b/src/org/kde/kdeconnect/Backends/BaseLinkProvider.java index 980aaec6..cfaf621d 100644 --- a/src/org/kde/kdeconnect/Backends/BaseLinkProvider.java +++ b/src/org/kde/kdeconnect/Backends/BaseLinkProvider.java @@ -46,13 +46,13 @@ public abstract class BaseLinkProvider { //These two should be called when the provider links to a new computer protected void connectionAccepted(NetworkPackage identityPackage, BaseLink link) { - Log.i("LinkProvider", "connectionAccepted"); + //Log.i("KDE/LinkProvider", "connectionAccepted"); for(ConnectionReceiver cr : connectionReceivers) { cr.onConnectionReceived(identityPackage, link); } } protected void connectionLost(BaseLink link) { - Log.i("LinkProvider", "connectionLost"); + //Log.i("KDE/LinkProvider", "connectionLost"); for(ConnectionReceiver cr : connectionReceivers) { cr.onConnectionLost(link); } diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java index 2da5922d..9ba2bc42 100644 --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java @@ -47,8 +47,10 @@ public class LanLink extends BaseLink { private IoSession session = null; public void disconnect() { - if (session == null) return; - //Log.i("LanLink", "Disconnect: "+session.getRemoteAddress().toString()); + if (session == null) { + Log.e("KDE/LanLink", "Not yet connected"); + return; + } session.close(true); } @@ -60,7 +62,7 @@ public class LanLink extends BaseLink { //Blocking, do not call from main thread private void sendPackageInternal(NetworkPackage np, final Device.SendPackageStatusCallback callback, PublicKey key) { if (session == null) { - Log.e("sendPackage", "Not yet connected"); + Log.e("KDE/sendPackage", "Not yet connected"); callback.sendFailure(new NotYetConnectedException()); return; } @@ -87,7 +89,7 @@ public class LanLink extends BaseLink { WriteFuture future = session.write(np.serialize()); future.awaitUninterruptibly(); if (!future.isWritten()) { - Log.e("sendPackage", "!future.isWritten()"); + Log.e("KDE/sendPackage", "!future.isWritten()"); callback.sendFailure(future.getException()); return; } @@ -101,7 +103,7 @@ public class LanLink extends BaseLink { timeout.schedule(new TimerTask() { @Override public void run() { - Log.e("sendPackage","Timeout"); + Log.e("KDE/sendPackage","Timeout"); try { server.close(); } catch (Exception e) { } callback.sendFailure(new TimeoutException("Timed out waiting for other end to establish a connection to receive the payload.")); } @@ -109,7 +111,7 @@ public class LanLink extends BaseLink { socket = server.accept().getOutputStream(); timeout.cancel(); - Log.i("LanLink", "Beginning to send payload"); + Log.i("KDE/LanLink", "Beginning to send payload"); byte[] buffer = new byte[4096]; int bytesRead; @@ -123,9 +125,9 @@ public class LanLink extends BaseLink { callback.sendProgress((int)(progress / np.getPayloadSize())); } } - Log.i("LanLink", "Finished sending payload"); + Log.i("KDE/LanLink", "Finished sending payload"); } catch (Exception e) { - Log.e("sendPackage", "Exception: "+e); + Log.e("KDE/sendPackage", "Exception: "+e); callback.sendFailure(e); return; } finally { @@ -167,7 +169,7 @@ public class LanLink extends BaseLink { np = np.decrypt(privateKey); } catch(Exception e) { e.printStackTrace(); - Log.e("onPackageReceived","Exception reading the key needed to decrypt the package"); + Log.e("KDE/onPackageReceived","Exception reading the key needed to decrypt the package"); } } @@ -182,7 +184,7 @@ public class LanLink extends BaseLink { np.setPayload(socket.getInputStream(), np.getPayloadSize()); } catch (Exception e) { e.printStackTrace(); - Log.e("LanLink", "Exception connecting to payload remote socket"); + Log.e("KDE/LanLink", "Exception connecting to payload remote socket"); } } @@ -200,12 +202,12 @@ public class LanLink extends BaseLink { candidateServer = new ServerSocket(); candidateServer.bind(new InetSocketAddress(tcpPort)); success = true; - Log.i("LanLink", "Using port "+tcpPort); + Log.i("KDE/LanLink", "Using port "+tcpPort); } catch(IOException e) { //Log.e("LanLink", "Exception openning serversocket: "+e); tcpPort++; if (tcpPort >= 1764) { - Log.e("LanLink", "No more ports available"); + Log.e("KDE/LanLink", "No more ports available"); throw e; } } diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java index 56564351..80a78bc1 100644 --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java @@ -100,7 +100,7 @@ public class LanLinkProvider extends BaseLinkProvider { String theMessage = (String) message; if (theMessage.isEmpty()) { - Log.e("LanLinkProvider","Empty package received"); + Log.e("KDE/LanLinkProvider","Empty package received"); return; } @@ -113,15 +113,16 @@ public class LanLinkProvider extends BaseLinkProvider { return; } - //Log.e("LanLinkProvider", "Identity package received from "+np.getString("deviceName")); + //Log.i("KDE/LanLinkProvider", "Identity package received from " + np.getString("deviceName")); LanLink link = new LanLink(session, np.getString("deviceId"), LanLinkProvider.this); nioSessions.put(session.getId(),link); + //Log.e("KDE/LanLinkProvider","nioSessions.size(): " + nioSessions.size()); addLink(np, link); } else { LanLink prevLink = nioSessions.get(session.getId()); if (prevLink == null) { - Log.e("LanLinkProvider","2 Expecting an identity package"); + Log.e("KDE/LanLinkProvider","Expecting an identity package (A)"); } else { prevLink.injectNetworkPackage(np); } @@ -143,7 +144,7 @@ public class LanLinkProvider extends BaseLinkProvider { final NetworkPackage identityPackage = NetworkPackage.unserialize(theMessage); if (!identityPackage.getType().equals(NetworkPackage.PACKAGE_TYPE_IDENTITY)) { - Log.e("LanLinkProvider", "1 Expecting an identity package"); + Log.e("KDE/LanLinkProvider", "Expecting an identity package (B)"); return; } else { String myId = NetworkPackage.createIdentityPackage(context).getString("deviceId"); @@ -152,7 +153,7 @@ public class LanLinkProvider extends BaseLinkProvider { } } - Log.i("LanLinkProvider", "Identity package received, creating link"); + //Log.i("KDE/LanLinkProvider", "Identity package received, creating link"); final InetSocketAddress address = (InetSocketAddress) udpSession.getRemoteAddress(); @@ -199,7 +200,7 @@ public class LanLinkProvider extends BaseLinkProvider { }); } catch (Exception e) { - Log.e("LanLinkProvider","Exception receiving udp package!!"); + Log.e("KDE/LanLinkProvider","Exception receiving udp package!!"); e.printStackTrace(); } @@ -208,16 +209,16 @@ public class LanLinkProvider extends BaseLinkProvider { private void addLink(NetworkPackage identityPackage, LanLink link) { String deviceId = identityPackage.getString("deviceId"); - Log.i("LanLinkProvider","addLink to "+deviceId); + Log.i("KDE/LanLinkProvider","addLink to "+deviceId); LanLink oldLink = visibleComputers.get(deviceId); if (oldLink == link) { - Log.e("KDEConnect", "LanLinkProvider: oldLink == link. This should not happen!"); + Log.e("KDE/LanLinkProvider", "oldLink == link. This should not happen!"); return; } visibleComputers.put(deviceId, link); connectionAccepted(identityPackage, link); if (oldLink != null) { - Log.i("LanLinkProvider","Removing old connection to same device"); + Log.i("KDE/LanLinkProvider","Removing old connection to same device"); oldLink.disconnect(); connectionLost(oldLink); } @@ -261,7 +262,7 @@ public class LanLinkProvider extends BaseLinkProvider { try { udpAcceptor.bind(new InetSocketAddress(port)); } catch(Exception e) { - Log.e("LanLinkProvider", "Error: Could not bind udp socket"); + Log.e("KDE/LanLinkProvider", "Error: Could not bind udp socket"); e.printStackTrace(); } @@ -276,7 +277,7 @@ public class LanLinkProvider extends BaseLinkProvider { } } - Log.i("LanLinkProvider","Using tcpPort "+tcpPort); + Log.i("KDE/LanLinkProvider","Using tcpPort "+tcpPort); //I'm on a new network, let's be polite and introduce myself final int finalTcpPort = tcpPort; @@ -301,10 +302,10 @@ public class LanLinkProvider extends BaseLinkProvider { socket.setReuseAddress(true); socket.setBroadcast(true); socket.send(packet); - //Log.i("LanLinkProvider","Udp identity package sent to address "+packet.getAddress()); + //Log.i("KDE/LanLinkProvider","Udp identity package sent to address "+packet.getAddress()); } catch(Exception e) { e.printStackTrace(); - Log.e("LanLinkProvider","Sending udp identity package failed. Invalid address? ("+ipstr+")"); + Log.e("KDE/LanLinkProvider","Sending udp identity package failed. Invalid address? ("+ipstr+")"); } } @@ -318,8 +319,12 @@ public class LanLinkProvider extends BaseLinkProvider { @Override public void onNetworkChange() { + //Log.e("KDE/LanLinkProvider","onNetworkChange"); + //FilesHelper.LogOpenFileCount(); onStop(); + //FilesHelper.LogOpenFileCount(); onStart(); + //FilesHelper.LogOpenFileCount(); } @Override diff --git a/src/org/kde/kdeconnect/BackgroundService.java b/src/org/kde/kdeconnect/BackgroundService.java index c550067b..855a52d1 100644 --- a/src/org/kde/kdeconnect/BackgroundService.java +++ b/src/org/kde/kdeconnect/BackgroundService.java @@ -105,17 +105,17 @@ public class BackgroundService extends Service { @Override public void onConnectionReceived(final NetworkPackage identityPackage, final BaseLink link) { - Log.i("BackgroundService", "Connection accepted!"); + Log.i("KDE/BackgroundService", "Connection accepted!"); String deviceId = identityPackage.getString("deviceId"); Device device = devices.get(deviceId); if (device != null) { - Log.i("BackgroundService", "addLink, known device: " + deviceId); + Log.i("KDE/BackgroundService", "addLink, known device: " + deviceId); device.addLink(identityPackage, link); } else { - Log.i("BackgroundService", "addLink,unknown device: " + deviceId); + Log.i("KDE/BackgroundService", "addLink,unknown device: " + deviceId); device = new Device(BackgroundService.this, identityPackage, link); devices.put(deviceId, device); device.addPairingCallback(devicePairingCallback); @@ -127,7 +127,7 @@ public class BackgroundService extends Service { @Override public void onConnectionLost(BaseLink link) { Device d = devices.get(link.getDeviceId()); - Log.i("onConnectionLost", "removeLink, deviceId: " + link.getDeviceId()); + Log.i("KDE/onConnectionLost", "removeLink, deviceId: " + link.getDeviceId()); if (d != null) { d.removeLink(link); if (!d.isReachable() && !d.isPaired()) { @@ -136,7 +136,7 @@ public class BackgroundService extends Service { d.removePairingCallback(devicePairingCallback); } } else { - Log.e("onConnectionLost","Removing connection to unknown device, this should not happen"); + Log.e("KDE/onConnectionLost","Removing connection to unknown device, this should not happen"); } if (deviceListChangedCallback != null) deviceListChangedCallback.onDeviceListChanged(); } @@ -147,34 +147,35 @@ public class BackgroundService extends Service { } public void startDiscovery() { - Log.i("BackgroundService","StartDiscovery"); + Log.i("KDE/BackgroundService","StartDiscovery"); for (BaseLinkProvider a : linkProviders) { a.onStart(); } } public void stopDiscovery() { - Log.i("BackgroundService","StopDiscovery"); + Log.i("KDE/BackgroundService","StopDiscovery"); for (BaseLinkProvider a : linkProviders) { a.onStop(); } } public void onNetworkChange() { - Log.i("BackgroundService","OnNetworkChange"); + Log.i("KDE/BackgroundService","OnNetworkChange"); for (BaseLinkProvider a : linkProviders) { a.onNetworkChange(); } } public void addConnectionListener(BaseLinkProvider.ConnectionReceiver cr) { - Log.i("BackgroundService","Registering connection listener"); + Log.i("KDE/BackgroundService","Registering connection listener"); for (BaseLinkProvider a : linkProviders) { a.addConnectionReceiver(cr); } } public void removeConnectionListener(BaseLinkProvider.ConnectionReceiver cr) { + Log.i("KDE/BackgroundService","Removing connection listener"); for (BaseLinkProvider a : linkProviders) { a.removeConnectionReceiver(cr); } @@ -198,7 +199,7 @@ public class BackgroundService extends Service { IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); registerReceiver(new KdeConnectBroadcastReceiver(), filter); - Log.i("BackgroundService","Service not started yet, initializing..."); + Log.i("KDE/BackgroundService","Service not started yet, initializing..."); initializeRsaKeys(); MainSettingsActivity.initializeDeviceName(this); @@ -223,7 +224,7 @@ public class BackgroundService extends Service { keyPair = keyGen.genKeyPair(); } catch(Exception e) { e.printStackTrace(); - Log.e("initializeRsaKeys","Exception"); + Log.e("KDE/initializeRsaKeys","Exception"); return; } @@ -268,7 +269,7 @@ public class BackgroundService extends Service { @Override public void onDestroy() { - Log.i("BackgroundService", "Destroying"); + Log.i("KDE/BackgroundService", "Destroying"); stopDiscovery(); super.onDestroy(); } diff --git a/src/org/kde/kdeconnect/Device.java b/src/org/kde/kdeconnect/Device.java index 585c05d9..c9dd85b3 100644 --- a/src/org/kde/kdeconnect/Device.java +++ b/src/org/kde/kdeconnect/Device.java @@ -102,7 +102,7 @@ public class Device implements BaseLink.PackageReceiver { publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyBytes)); } catch (Exception e) { e.printStackTrace(); - Log.e("Device","Exception"); + Log.e("KDE/Device","Exception"); } reloadPluginsFromSettings(); @@ -200,7 +200,7 @@ public class Device implements BaseLink.PackageReceiver { for (PairingCallback cb : pairingCallback) { cb.pairingFailed(context.getString(R.string.error_timed_out)); } - Log.e("Device","Unpairing (timeout A)"); + Log.e("KDE/Device","Unpairing (timeout A)"); pairStatus = PairStatus.NotPaired; } }, 30*1000); //Time to wait for the other to accept @@ -212,7 +212,7 @@ public class Device implements BaseLink.PackageReceiver { for (PairingCallback cb : pairingCallback) { cb.pairingFailed(context.getString(R.string.error_could_not_send_package)); } - Log.e("Device","Unpairing (sendFailed A)"); + Log.e("KDE/Device","Unpairing (sendFailed A)"); pairStatus = PairStatus.NotPaired; } @@ -271,7 +271,7 @@ public class Device implements BaseLink.PackageReceiver { public void acceptPairing() { - Log.i("Device","Accepted pair request started by the other device"); + Log.i("KDE/Device","Accepted pair request started by the other device"); //Send our own public key NetworkPackage np = NetworkPackage.createPublicKeyPackage(context); @@ -294,7 +294,7 @@ public class Device implements BaseLink.PackageReceiver { public void rejectPairing() { - Log.i("Device","Rejected pair request started by the other device"); + Log.i("KDE/Device","Rejected pair request started by the other device"); //Log.e("Device","Unpairing (rejectPairing)"); pairStatus = PairStatus.NotPaired; @@ -321,6 +321,7 @@ public class Device implements BaseLink.PackageReceiver { } public void addLink(NetworkPackage identityPackage, BaseLink link) { + //FilesHelper.LogOpenFileCount(); this.protocolVersion = identityPackage.getInt("protocolVersion"); @@ -341,10 +342,10 @@ public class Device implements BaseLink.PackageReceiver { link.setPrivateKey(privateKey); } catch (Exception e) { e.printStackTrace(); - Log.e("Device", "Exception reading our own private key"); //Should not happen + Log.e("KDE/Device", "Exception reading our own private key"); //Should not happen } - Log.i("Device","addLink "+link.getLinkProvider().getName()+" -> "+getName() + " active links: "+ links.size()); + Log.i("KDE/Device","addLink "+link.getLinkProvider().getName()+" -> "+getName() + " active links: "+ links.size()); /* Collections.sort(links, new Comparator() { @@ -363,9 +364,11 @@ public class Device implements BaseLink.PackageReceiver { } public void removeLink(BaseLink link) { + //FilesHelper.LogOpenFileCount(); + link.removePackageReceiver(this); links.remove(link); - Log.i("Device","removeLink: "+link.getLinkProvider().getName() + " -> "+getName() + " active links: "+ links.size()); + Log.i("KDE/Device","removeLink: "+link.getLinkProvider().getName() + " -> "+getName() + " active links: "+ links.size()); if (links.isEmpty()) { reloadPluginsFromSettings(); } @@ -376,7 +379,7 @@ public class Device implements BaseLink.PackageReceiver { if (np.getType().equals(NetworkPackage.PACKAGE_TYPE_PAIR)) { - Log.i("Device","Pair package"); + Log.i("KDE/Device","Pair package"); boolean wantsPair = np.getBoolean("pair"); @@ -401,7 +404,7 @@ public class Device implements BaseLink.PackageReceiver { publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyBytes)); } catch(Exception e) { e.printStackTrace(); - Log.e("Device","Pairing exception: Received incorrect key"); + Log.e("KDE/Device","Pairing exception: Received incorrect key"); for (PairingCallback cb : pairingCallback) { cb.pairingFailed(context.getString(R.string.error_invalid_key)); } @@ -410,7 +413,7 @@ public class Device implements BaseLink.PackageReceiver { if (pairStatus == PairStatus.Requested) { //We started pairing - Log.i("Pairing","Pair answer"); + Log.i("KDE/Pairing","Pair answer"); if (pairingTimer != null) pairingTimer.cancel(); @@ -418,7 +421,7 @@ public class Device implements BaseLink.PackageReceiver { } else { - Log.i("Pairing","Pair request"); + Log.i("KDE/Pairing","Pair request"); Intent intent = new Intent(context, PairActivity.class); intent.putExtra("deviceId", deviceId); @@ -447,7 +450,7 @@ public class Device implements BaseLink.PackageReceiver { pairingTimer.schedule(new TimerTask() { @Override public void run() { - Log.e("Device","Unpairing (timeout B)"); + Log.e("KDE/Device","Unpairing (timeout B)"); pairStatus = PairStatus.NotPaired; notificationManager.cancel(notificationId); } @@ -457,7 +460,7 @@ public class Device implements BaseLink.PackageReceiver { } } else { - Log.i("Pairing","Unpair request"); + Log.i("KDE/Pairing","Unpair request"); if (pairStatus == PairStatus.Requested) { pairingTimer.cancel(); @@ -470,7 +473,6 @@ public class Device implements BaseLink.PackageReceiver { reloadPluginsFromSettings(); } - //Log.e("Device","Unpairing (unpair request)"); pairStatus = PairStatus.NotPaired; for (PairingCallback cb : pairingCallback) cb.unpaired(); @@ -482,14 +484,14 @@ public class Device implements BaseLink.PackageReceiver { plugin.onPackageReceived(np); } catch (Exception e) { e.printStackTrace(); - Log.e("Device", "Exception in "+plugin.getDisplayName()+"'s onPackageReceived()"); + Log.e("KDE/Device", "Exception in "+plugin.getDisplayName()+"'s onPackageReceived()"); } } } else { - Log.e("onPackageReceived","Device not paired, ignoring package!"); + Log.e("KDE/onPackageReceived","Device not paired, ignoring package!"); if (pairStatus != PairStatus.Requested) { unpair(); @@ -512,9 +514,9 @@ public class Device implements BaseLink.PackageReceiver { public void sendFailure(Throwable e) { if (e != null) { e.printStackTrace(); - Log.e("sendPackage", "Exception: " + e.getMessage()); + Log.e("KDE/sendPackage", "Exception: " + e.getMessage()); } else { - Log.e("sendPackage", "Unknown (null) exception"); + Log.e("KDE/sendPackage", "Unknown (null) exception"); } onFailure(e); } @@ -556,7 +558,7 @@ public class Device implements BaseLink.PackageReceiver { } if (!callback.success) { - Log.e("sendPackage", "No device link (of "+mLinks.size()+" available) could send the package. Package lost!"); + Log.e("KDE/sendPackage", "No device link (of "+mLinks.size()+" available) could send the package. Package lost!"); backtrace.printStackTrace(); } @@ -584,13 +586,13 @@ public class Device implements BaseLink.PackageReceiver { private synchronized void addPlugin(final String name) { Plugin existing = plugins.get(name); if (existing != null) { - Log.w("addPlugin","plugin already present:" + name); + Log.w("KDE/addPlugin","plugin already present:" + name); return; } final Plugin plugin = PluginFactory.instantiatePluginForDevice(context, name, this); if (plugin == null) { - Log.e("addPlugin","could not instantiate plugin: "+name); + Log.e("KDE/addPlugin","could not instantiate plugin: "+name); failedPlugins.put(name, plugin); return; } @@ -605,7 +607,7 @@ public class Device implements BaseLink.PackageReceiver { } catch (Exception e) { success = false; e.printStackTrace(); - Log.e("addPlugin", "Exception loading plugin " + name); + Log.e("KDE/addPlugin", "Exception loading plugin " + name); } if (success) { @@ -613,7 +615,7 @@ public class Device implements BaseLink.PackageReceiver { failedPlugins.remove(name); plugins.put(name, plugin); } else { - Log.e("addPlugin", "plugin failed to load " + name); + Log.e("KDE/addPlugin", "plugin failed to load " + name); plugins.remove(name); failedPlugins.put(name, plugin); } @@ -645,7 +647,7 @@ public class Device implements BaseLink.PackageReceiver { //Log.e("removePlugin","removed " + name); } catch (Exception e) { e.printStackTrace(); - Log.e("removePlugin","Exception calling onDestroy for plugin "+name); + Log.e("KDE/removePlugin","Exception calling onDestroy for plugin "+name); } for (PluginsChangedListener listener : pluginsChangedListeners) { diff --git a/src/org/kde/kdeconnect/Helpers/FilesHelper.java b/src/org/kde/kdeconnect/Helpers/FilesHelper.java index 6ed7701f..b5347c93 100644 --- a/src/org/kde/kdeconnect/Helpers/FilesHelper.java +++ b/src/org/kde/kdeconnect/Helpers/FilesHelper.java @@ -20,8 +20,11 @@ package org.kde.kdeconnect.Helpers; +import android.util.Log; import android.webkit.MimeTypeMap; +import java.io.File; + public class FilesHelper { public static String getFileExt(String fileName) { @@ -73,4 +76,11 @@ public class FilesHelper { return toFileSystemSafeName(name, true, 255); } + public static int GetOpenFileCount() { + return new File("/proc/self/fd").listFiles().length; + } + + public static void LogOpenFileCount() { + Log.e("KDE/FileCount",""+GetOpenFileCount()); + } }