From f1194e88c29453a1069e5a408a3ff20ffc8a7b55 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Sun, 31 Mar 2019 20:09:44 +0200 Subject: [PATCH] Use Log.e instead of printStackTrace --- .../BluetoothLinkProvider.java | 4 +- .../Backends/LanBackend/LanLink.java | 8 ++-- .../Backends/LanBackend/LanLinkProvider.java | 37 +++++++------------ .../LanBackend/LanPairingHandler.java | 21 +++-------- src/org/kde/kdeconnect/Device.java | 32 +++++----------- .../kde/kdeconnect/Helpers/AppsHelper.java | 12 +----- .../kdeconnect/Helpers/ContactsHelper.java | 6 +-- .../kde/kdeconnect/Helpers/DeviceHelper.java | 3 +- .../kde/kdeconnect/Helpers/FilesHelper.java | 10 ++--- .../kde/kdeconnect/Helpers/NetworkHelper.java | 6 +-- .../Helpers/SecurityHelpers/RsaHelper.java | 3 +- .../Helpers/SecurityHelpers/SslHelper.java | 9 ++--- .../kde/kdeconnect/Helpers/StorageHelper.java | 5 ++- src/org/kde/kdeconnect/NetworkPacket.java | 3 +- .../Plugins/MprisPlugin/MprisPlugin.java | 9 ++--- .../NotificationsPlugin.java | 15 +++----- .../kde/kdeconnect/Plugins/PluginFactory.java | 3 +- .../RunCommandPlugin/RunCommandActivity.java | 3 +- .../RunCommandPlugin/RunCommandPlugin.java | 5 ++- .../Plugins/SMSPlugin/SMSPlugin.java | 3 +- .../Plugins/SftpPlugin/SftpPlugin.java | 3 +- .../SftpPlugin/SftpSettingsFragment.java | 3 +- .../Plugins/SftpPlugin/SimpleSftpServer.java | 3 +- .../NotificationUpdateCallback.java | 5 +-- .../Plugins/SharePlugin/SharePlugin.java | 8 ++-- .../SharePlugin/ShareSettingsFragment.java | 2 +- .../SystemVolumePlugin.java | 4 +- .../UserInterface/DeviceFragment.java | 1 - .../UserInterface/PairingFragment.java | 1 - tests/org/kde/kdeconnect/DeviceTest.java | 12 +++--- tests/org/kde/kdeconnect/LanLinkTest.java | 8 ++-- 31 files changed, 90 insertions(+), 157 deletions(-) diff --git a/src/org/kde/kdeconnect/Backends/BluetoothBackend/BluetoothLinkProvider.java b/src/org/kde/kdeconnect/Backends/BluetoothBackend/BluetoothLinkProvider.java index bb896db8..68556d76 100644 --- a/src/org/kde/kdeconnect/Backends/BluetoothBackend/BluetoothLinkProvider.java +++ b/src/org/kde/kdeconnect/Backends/BluetoothBackend/BluetoothLinkProvider.java @@ -149,7 +149,7 @@ public class BluetoothLinkProvider extends BaseLinkProvider { try { serverSocket.close(); } catch (IOException e) { - e.printStackTrace(); + Log.e("KDEConnect", "Exception", e); } } } @@ -160,7 +160,7 @@ public class BluetoothLinkProvider extends BaseLinkProvider { serverSocket = bluetoothAdapter .listenUsingRfcommWithServiceRecord("KDE Connect", SERVICE_UUID); } catch (IOException e) { - e.printStackTrace(); + Log.e("KDEConnect", "Exception", e); return; } diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java index 3b0dc707..b82434c0 100644 --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java @@ -71,7 +71,7 @@ public class LanLink extends BaseLink { try { socket.close(); } catch (IOException e) { - e.printStackTrace(); + Log.e("LanLink", "Error", e); } } @@ -257,8 +257,7 @@ public class LanLink extends BaseLink { try { np = RsaHelper.decrypt(np, privateKey); } catch(Exception e) { - e.printStackTrace(); - Log.e("KDE/onPacketReceived","Exception decrypting the package"); + Log.e("KDE/onPacketReceived","Exception decrypting the package", e); } } @@ -275,8 +274,7 @@ public class LanLink extends BaseLink { np.setPayload(new NetworkPacket.Payload(payloadSocket, np.getPayloadSize())); } catch (Exception e) { try { payloadSocket.close(); } catch(Exception ignored) { } - e.printStackTrace(); - Log.e("KDE/LanLink", "Exception connecting to payload remote socket"); + Log.e("KDE/LanLink", "Exception connecting to payload remote socket", e); } } diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java index 6d331c84..74a93555 100644 --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java @@ -102,7 +102,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis networkPacket = NetworkPacket.unserialize(message); //Log.e("TcpListener","Received TCP package: "+networkPacket.serialize()); } catch (Exception e) { - e.printStackTrace(); + Log.e("KDE/LanLinkProvider", "Exception while receiving TCP packet", e); return; } @@ -157,8 +157,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis identityPacketReceived(identityPacket, socket, LanLink.ConnectionStarted.Remotely); } catch (Exception e) { - Log.e("KDE/LanLinkProvider", "Cannot connect to " + address); - e.printStackTrace(); + Log.e("KDE/LanLinkProvider", "Cannot connect to " + address, e); if (!reverseConnectionBlackList.contains(address)) { Log.w("KDE/LanLinkProvider", "Blacklisting " + address); reverseConnectionBlackList.add(address); @@ -179,7 +178,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis try { socket.setKeepAlive(true); } catch (SocketException e) { - e.printStackTrace(); + Log.e("LanLink", "Exception", e); } } @@ -236,8 +235,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis Log.i("KDE/LanLinkProvider", "Handshake as " + mode + " successful with " + identityPacket.getString("deviceName") + " secured with " + event.getCipherSuite()); addLink(identityPacket, sslsocket, connectionStarted); } catch (Exception e) { - Log.e("KDE/LanLinkProvider", "Handshake as " + mode + " failed with " + identityPacket.getString("deviceName")); - e.printStackTrace(); + Log.e("KDE/LanLinkProvider", "Handshake as " + mode + " failed with " + identityPacket.getString("deviceName"), e); BackgroundService.RunCommand(context, service -> { Device device = service.getDevice(deviceId); if (device == null) return; @@ -252,8 +250,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis sslsocket.startHandshake(); } } catch (Exception e) { - Log.e("KDE/LanLinkProvider", "Handshake failed with " + identityPacket.getString("deviceName")); - e.printStackTrace(); + Log.e("KDE/LanLinkProvider", "Handshake failed with " + identityPacket.getString("deviceName"), e); //String[] ciphers = sslsocket.getSupportedCipherSuites(); //for (String cipher : ciphers) { @@ -265,7 +262,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis addLink(identityPacket, socket, connectionStarted); } } catch (Exception e) { - e.printStackTrace(); + Log.e("LanLink", "Exception", e); } } @@ -311,8 +308,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis udpServer.setReuseAddress(true); udpServer.setBroadcast(true); } catch (SocketException e) { - Log.e("LanLinkProvider", "Error creating udp server"); - e.printStackTrace(); + Log.e("LanLinkProvider", "Error creating udp server", e); return; } new Thread(() -> { @@ -324,8 +320,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis udpServer.receive(packet); udpPacketReceived(packet); } catch (Exception e) { - e.printStackTrace(); - Log.e("LanLinkProvider", "UdpReceive exception"); + Log.e("LanLinkProvider", "UdpReceive exception", e); } } Log.w("UdpListener", "Stopping UDP listener"); @@ -336,8 +331,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis try { tcpServer = openServerSocketOnFreePort(MIN_PORT); } catch (Exception e) { - Log.e("LanLinkProvider", "Error creating tcp server"); - e.printStackTrace(); + Log.e("LanLinkProvider", "Error creating tcp server", e); return; } new Thread(() -> { @@ -347,8 +341,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis configureSocket(socket); tcpPacketReceived(socket); } catch (Exception e) { - e.printStackTrace(); - Log.e("LanLinkProvider", "TcpReceive exception"); + Log.e("LanLinkProvider", "TcpReceive exception", e); } } Log.w("TcpListener", "Stopping TCP listener"); @@ -398,8 +391,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis socket.setBroadcast(true); bytes = identity.serialize().getBytes(StringsHelper.UTF8); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/LanLinkProvider", "Failed to create DatagramSocket"); + Log.e("KDE/LanLinkProvider", "Failed to create DatagramSocket", e); } if (bytes != null) { @@ -410,8 +402,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis socket.send(new DatagramPacket(bytes, bytes.length, client, MIN_PORT)); //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 + ")"); + Log.e("KDE/LanLinkProvider", "Sending udp identity package failed. Invalid address? (" + ipstr + ")", e); } } } @@ -449,12 +440,12 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis try { tcpServer.close(); } catch (Exception e) { - e.printStackTrace(); + Log.e("LanLink", "Exception", e); } try { udpServer.close(); } catch (Exception e) { - e.printStackTrace(); + Log.e("LanLink", "Exception", e); } } diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanPairingHandler.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanPairingHandler.java index 3160f765..049efa93 100644 --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanPairingHandler.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanPairingHandler.java @@ -158,11 +158,7 @@ public class LanPairingHandler extends BasePairingHandler { @Override public void onFailure(Throwable e) { - if (e != null) { - e.printStackTrace(); - } else { - Log.e("LanPairing/onFailure", "Unknown (null) exception"); - } + Log.e("LanPairing/onFailure", "Exception", e); mCallback.pairingFailed(mDevice.getContext().getString(R.string.error_could_not_send_package)); } }; @@ -187,11 +183,7 @@ public class LanPairingHandler extends BasePairingHandler { @Override public void onFailure(Throwable e) { - if (e != null) { - e.printStackTrace(); - } else { - Log.e("LanPairing/onFailure", "Unknown (null) exception"); - } + Log.e("LanPairing/onFailure", "Exception", e); mCallback.pairingFailed(mDevice.getContext().getString(R.string.error_not_reachable)); } }; @@ -217,7 +209,7 @@ public class LanPairingHandler extends BasePairingHandler { String encodedPublicKey = Base64.encodeToString(mDevice.publicKey.getEncoded(), 0); editor.putString("publicKey", encodedPublicKey); } catch (Exception e) { - Log.e("KDE/PairingDone", "Error encoding public key"); + Log.e("KDE/PairingDone", "Error encoding public key", e); } } @@ -225,12 +217,11 @@ public class LanPairingHandler extends BasePairingHandler { String encodedCertificate = Base64.encodeToString(mDevice.certificate.getEncoded(), 0); editor.putString("certificate", encodedCertificate); } catch (NullPointerException n) { - Log.w("KDE/PairingDone", "Certificate is null, remote device does not support ssl"); + Log.w("KDE/PairingDone", "Certificate is null, remote device does not support ssl", n); } catch (CertificateEncodingException c) { - Log.e("KDE/PairingDOne", "Error encoding certificate"); + Log.e("KDE/PairingDOne", "Error encoding certificate", c); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/Pairng", "Exception"); + Log.e("KDE/Pairng", "Exception", e); } editor.apply(); diff --git a/src/org/kde/kdeconnect/Device.java b/src/org/kde/kdeconnect/Device.java index 69c5a76d..811379e9 100644 --- a/src/org/kde/kdeconnect/Device.java +++ b/src/org/kde/kdeconnect/Device.java @@ -157,8 +157,7 @@ public class Device implements BaseLink.PacketReceiver { publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyBytes)); } } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/Device", "Exception deserializing stored public key for device"); + Log.e("KDE/Device", "Exception deserializing stored public key for device", e); } //Assume every plugin is supported until addLink is called and we can get the actual list @@ -459,8 +458,7 @@ public class Device implements BaseLink.PacketReceiver { certificate = SslHelper.parseCertificate(certificateBytes); Log.i("KDE/Device", "Got certificate "); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/Device", "Error getting certificate"); + Log.e("KDE/Device", "Error getting certificate", e); } } @@ -474,8 +472,7 @@ public class Device implements BaseLink.PacketReceiver { PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(privateKeyBytes)); link.setPrivateKey(privateKey); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/Device", "Exception reading our own private key"); //Should not happen + Log.e("KDE/Device", "Exception reading our own private key", e); //Should not happen } Log.i("KDE/Device", "addLink " + link.getLinkProvider().getName() + " -> " + getName() + " active links: " + links.size()); @@ -559,8 +556,7 @@ public class Device implements BaseLink.PacketReceiver { try { ph.packageReceived(np); } catch (Exception e) { - e.printStackTrace(); - Log.e("PairingPacketReceived", "Exception"); + Log.e("PairingPacketReceived", "Exception", e); } } } else if (isPaired()) { @@ -578,8 +574,7 @@ public class Device implements BaseLink.PacketReceiver { try { plugin.onPacketReceived(np); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/Device", "Exception in " + plugin.getPluginKey() + "'s onPacketReceived()"); + Log.e("KDE/Device", "Exception in " + plugin.getPluginKey() + "'s onPacketReceived()", e); //try { Log.e("KDE/Device", "NetworkPacket:" + np.serialize()); } catch (Exception _) { } } } @@ -604,8 +599,7 @@ public class Device implements BaseLink.PacketReceiver { try { plugin.onUnpairedDevicePacketReceived(np); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/Device", "Exception in " + plugin.getDisplayName() + "'s onPacketReceived() in unPairedPacketListeners"); + Log.e("KDE/Device", "Exception in " + plugin.getDisplayName() + "'s onPacketReceived() in unPairedPacketListeners", e); } } } else { @@ -631,11 +625,7 @@ public class Device implements BaseLink.PacketReceiver { @Override public void onFailure(Throwable e) { - if (e != null) { - e.printStackTrace(); - } else { - Log.e("KDE/sendPacket", "Unknown (null) exception"); - } + Log.e("KDE/sendPacket", "Exception", e); } }; @@ -734,10 +724,7 @@ public class Device implements BaseLink.PacketReceiver { success = plugin.onCreate(); } catch (Exception e) { success = false; - e.printStackTrace(); - } - if (!success) { - Log.e("KDE/addPlugin", "plugin failed to load " + pluginKey); + Log.e("KDE/addPlugin", "plugin failed to load " + pluginKey, e); } plugins.put(pluginKey, plugin); @@ -775,8 +762,7 @@ public class Device implements BaseLink.PacketReceiver { plugin.onDestroy(); //Log.e("removePlugin","removed " + pluginKey); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/removePlugin", "Exception calling onDestroy for plugin " + pluginKey); + Log.e("KDE/removePlugin", "Exception calling onDestroy for plugin " + pluginKey, e); } return true; diff --git a/src/org/kde/kdeconnect/Helpers/AppsHelper.java b/src/org/kde/kdeconnect/Helpers/AppsHelper.java index 1c9f2f85..792b55ce 100644 --- a/src/org/kde/kdeconnect/Helpers/AppsHelper.java +++ b/src/org/kde/kdeconnect/Helpers/AppsHelper.java @@ -39,8 +39,7 @@ public class AppsHelper { } catch (final PackageManager.NameNotFoundException e) { - e.printStackTrace(); - Log.e("AppsHelper", "Could not resolve name " + packageName); + Log.e("AppsHelper", "Could not resolve name " + packageName, e); return null; @@ -57,15 +56,8 @@ public class AppsHelper { return pm.getApplicationIcon(ai); } catch (final PackageManager.NameNotFoundException e) { - - e.printStackTrace(); - Log.e("AppsHelper", "Could not find icon for " + packageName); - + Log.e("AppsHelper", "Could not find icon for " + packageName, e); return null; - } - } - - } diff --git a/src/org/kde/kdeconnect/Helpers/ContactsHelper.java b/src/org/kde/kdeconnect/Helpers/ContactsHelper.java index 718e2228..501783a8 100644 --- a/src/org/kde/kdeconnect/Helpers/ContactsHelper.java +++ b/src/org/kde/kdeconnect/Helpers/ContactsHelper.java @@ -191,7 +191,7 @@ public class ContactsHelper { } } catch (IOException e) { // If you are experiencing this, please open a bug report indicating how you got here - e.printStackTrace(); + Log.e("Contacts", "Exception while fetching vcards", e); } // At this point we are screwed: @@ -239,10 +239,10 @@ public class ContactsHelper { toReturn.put(ID, new VCardBuilder(vcard.toString())); } catch (IOException e) { // If you are experiencing this, please open a bug report indicating how you got here - e.printStackTrace(); + Log.e("Contacts", "Exception while fetching vcards", e); } catch (NullPointerException e) { // If you are experiencing this, please open a bug report indicating how you got here - e.printStackTrace(); + Log.e("Contacts", "Exception while fetching vcards", e); } } diff --git a/src/org/kde/kdeconnect/Helpers/DeviceHelper.java b/src/org/kde/kdeconnect/Helpers/DeviceHelper.java index b52e6903..9c157abc 100644 --- a/src/org/kde/kdeconnect/Helpers/DeviceHelper.java +++ b/src/org/kde/kdeconnect/Helpers/DeviceHelper.java @@ -496,8 +496,7 @@ public class DeviceHelper { } } catch (Exception e) { //Some phones might not define BRAND or MODEL, ignore exceptions - Log.e("Exception", e.getMessage()); - e.printStackTrace(); + Log.e("Exception", e.getMessage(), e); } if (deviceName == null || deviceName.isEmpty()) { return "Android"; //Could not find a name diff --git a/src/org/kde/kdeconnect/Helpers/FilesHelper.java b/src/org/kde/kdeconnect/Helpers/FilesHelper.java index 54fcc284..cd804f26 100644 --- a/src/org/kde/kdeconnect/Helpers/FilesHelper.java +++ b/src/org/kde/kdeconnect/Helpers/FilesHelper.java @@ -129,8 +129,7 @@ public class FilesHelper { try { size = new File(uri.getPath()).length(); } catch (Exception e) { - Log.e("SendFileActivity", "Could not obtain file size"); - e.printStackTrace(); + Log.e("SendFileActivity", "Could not obtain file size", e); } } else { @@ -155,8 +154,7 @@ public class FilesHelper { String name = cursor.getString(column_index); np.set("filename", name); } catch (Exception e) { - e.printStackTrace(); - Log.e("SendFileActivity", "Could not obtain file name"); + Log.e("SendFileActivity", "Could not obtain file name", e); } try { @@ -165,8 +163,7 @@ public class FilesHelper { //For some reason this size can differ from the actual file size! size = cursor.getInt(column_index); } catch (Exception e) { - Log.e("SendFileActivity", "Could not obtain file size"); - e.printStackTrace(); + Log.e("SendFileActivity", "Could not obtain file size", e); } } finally { try { @@ -182,7 +179,6 @@ public class FilesHelper { return np; } catch (Exception e) { Log.e("SendFileActivity", "Exception creating network packet", e); - e.printStackTrace(); return null; } } diff --git a/src/org/kde/kdeconnect/Helpers/NetworkHelper.java b/src/org/kde/kdeconnect/Helpers/NetworkHelper.java index ec907dcb..f14bd791 100644 --- a/src/org/kde/kdeconnect/Helpers/NetworkHelper.java +++ b/src/org/kde/kdeconnect/Helpers/NetworkHelper.java @@ -45,14 +45,12 @@ public class NetworkHelper { return false; //I have neighbours, so this doesn't look like a mobile network } } catch (Exception e) { - Log.e("NetworkHelper", "Exception reading procnetarp"); - e.printStackTrace(); + Log.e("NetworkHelper", "Exception reading procnetarp", e); } } return mobile; } catch (Exception e) { - e.printStackTrace(); - Log.d("isOnMobileNetwork", "Something went wrong, but this is non-critical."); + Log.e("isOnMobileNetwork", "Something went wrong, but this is non-critical.", e); } return false; } diff --git a/src/org/kde/kdeconnect/Helpers/SecurityHelpers/RsaHelper.java b/src/org/kde/kdeconnect/Helpers/SecurityHelpers/RsaHelper.java index e274aeb2..3244f375 100644 --- a/src/org/kde/kdeconnect/Helpers/SecurityHelpers/RsaHelper.java +++ b/src/org/kde/kdeconnect/Helpers/SecurityHelpers/RsaHelper.java @@ -55,8 +55,7 @@ public class RsaHelper { keyGen.initialize(2048); keyPair = keyGen.genKeyPair(); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/initializeRsaKeys", "Exception"); + Log.e("KDE/initializeRsaKeys", "Exception", e); return; } diff --git a/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java b/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java index d10fea7f..98b96074 100644 --- a/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java +++ b/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java @@ -114,8 +114,7 @@ public class SslHelper { edit.apply(); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/initialiseCert", "Exception"); + Log.e("KDE/initialiseCert", "Exception", e); } } else { @@ -125,8 +124,7 @@ public class SslHelper { X509CertificateHolder certificateHolder = new X509CertificateHolder(certificateBytes); certificate = new JcaX509CertificateConverter().setProvider(BC).getCertificate(certificateHolder); } catch (Exception e) { - Log.e("KDE/SslHelper", "Exception reading own certificate"); - e.printStackTrace(); + Log.e("KDE/SslHelper", "Exception reading own certificate", e); } } } @@ -195,8 +193,7 @@ public class SslHelper { } return tlsContext; } catch (Exception e) { - Log.e("KDE/SslHelper", "Error creating tls context"); - e.printStackTrace(); + Log.e("KDE/SslHelper", "Error creating tls context", e); } return null; diff --git a/src/org/kde/kdeconnect/Helpers/StorageHelper.java b/src/org/kde/kdeconnect/Helpers/StorageHelper.java index 67fde391..9d8ccff4 100644 --- a/src/org/kde/kdeconnect/Helpers/StorageHelper.java +++ b/src/org/kde/kdeconnect/Helpers/StorageHelper.java @@ -26,6 +26,7 @@ import android.net.Uri; import android.os.Build; import android.os.Environment; import android.provider.DocumentsContract; +import android.util.Log; import java.io.BufferedReader; import java.io.File; @@ -89,7 +90,7 @@ public class StorageHelper { try (Scanner scanner = new Scanner(new File("/proc/mounts"))) { mounts = scanner.useDelimiter("\\A").next(); } catch (Exception e) { - e.printStackTrace(); + Log.e("StorageHelper", "Exception while getting storageList", e); } File dirs[] = storage.listFiles(); @@ -129,7 +130,7 @@ public class StorageHelper { } } } catch (Exception e) { - e.printStackTrace(); + Log.e("StorageHelper", "Exception", e); } for (String line : entries) { diff --git a/src/org/kde/kdeconnect/NetworkPacket.java b/src/org/kde/kdeconnect/NetworkPacket.java index 369e2a47..fdb385f3 100644 --- a/src/org/kde/kdeconnect/NetworkPacket.java +++ b/src/org/kde/kdeconnect/NetworkPacket.java @@ -279,8 +279,7 @@ public class NetworkPacket { np.mBody.put("incomingCapabilities", new JSONArray(PluginFactory.getIncomingCapabilities())); np.mBody.put("outgoingCapabilities", new JSONArray(PluginFactory.getOutgoingCapabilities())); } catch (Exception e) { - e.printStackTrace(); - Log.e("NetworkPacakge", "Exception on createIdentityPacket"); + Log.e("NetworkPackage", "Exception on createIdentityPacket", e); } return np; diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java index 44e0d4e7..d60c7b69 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java @@ -307,8 +307,7 @@ public class MprisPlugin extends Plugin { try { playerStatusUpdated.get(key).dispatchMessage(new Message()); } catch (Exception e) { - e.printStackTrace(); - Log.e("MprisControl", "Exception"); + Log.e("MprisControl", "Exception", e); playerStatusUpdated.remove(key); } } @@ -355,8 +354,7 @@ public class MprisPlugin extends Plugin { try { playerListUpdated.get(key).dispatchMessage(new Message()); } catch (Exception e) { - e.printStackTrace(); - Log.e("MprisControl", "Exception"); + Log.e("MprisControl", "Exception", e); playerListUpdated.remove(key); } } @@ -468,8 +466,7 @@ public class MprisPlugin extends Plugin { try { playerStatusUpdated.get(key).dispatchMessage(new Message()); } catch (Exception e) { - e.printStackTrace(); - Log.e("MprisControl", "Exception"); + Log.e("MprisControl", "Exception", e); playerStatusUpdated.remove(key); } } diff --git a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java index 31e2a9e6..390ffe19 100644 --- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java @@ -256,8 +256,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. np.set("payloadHash", getChecksum(bitmapData)); } } catch (Exception e) { - e.printStackTrace(); - Log.e("NotificationsPlugin", "Error retrieving icon"); + Log.e("NotificationsPlugin", "Error retrieving icon", e); } } else { currentNotifications.add(key); @@ -379,8 +378,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. Bundle extras = notification.extras; title = extractStringFromExtra(extras, TITLE_KEY); } catch (Exception e) { - Log.w("NotificationPlugin", "problem parsing notification extras for " + notification.tickerText); - e.printStackTrace(); + Log.e("NotificationPlugin", "problem parsing notification extras for " + notification.tickerText, e); } } } @@ -407,8 +405,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. repliableNotification.tag = statusBarNotification.getTag();//TODO find how to pass Tag with sending PendingIntent, might fix Hangout problem } } catch (Exception e) { - Log.w("NotificationPlugin", "problem extracting notification wear for " + statusBarNotification.getNotification().tickerText); - e.printStackTrace(); + Log.e("NotificationPlugin", "problem extracting notification wear for " + statusBarNotification.getNotification().tickerText, e); } } } @@ -427,8 +424,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. Object extraTextExtra = extras.get(TEXT_KEY); if (extraTextExtra != null) text = extraTextExtra.toString(); } catch (Exception e) { - Log.w("NotificationPlugin", "problem parsing notification extras for " + notification.tickerText); - e.printStackTrace(); + Log.e("NotificationPlugin", "problem parsing notification extras for " + notification.tickerText, e); } } } @@ -476,8 +472,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. ticker = extraText; } } catch (Exception e) { - Log.w("NotificationPlugin", "problem parsing notification extras for " + notification.tickerText); - e.printStackTrace(); + Log.e("NotificationPlugin", "problem parsing notification extras for " + notification.tickerText, e); } } diff --git a/src/org/kde/kdeconnect/Plugins/PluginFactory.java b/src/org/kde/kdeconnect/Plugins/PluginFactory.java index bfb0fd85..5bde38a1 100644 --- a/src/org/kde/kdeconnect/Plugins/PluginFactory.java +++ b/src/org/kde/kdeconnect/Plugins/PluginFactory.java @@ -141,8 +141,7 @@ public class PluginFactory { plugin.setContext(context, device); return plugin; } catch (Exception e) { - Log.e("PluginFactory", "Could not instantiate plugin: " + pluginKey); - e.printStackTrace(); + Log.e("PluginFactory", "Could not instantiate plugin: " + pluginKey, e); return null; } } diff --git a/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandActivity.java b/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandActivity.java index 5b31bf4a..8e3d925b 100644 --- a/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandActivity.java +++ b/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandActivity.java @@ -25,6 +25,7 @@ import android.content.ClipboardManager; import android.content.Context; import android.os.Build; import android.os.Bundle; +import android.util.Log; import android.view.ContextMenu; import android.view.MenuInflater; import android.view.MenuItem; @@ -69,7 +70,7 @@ public class RunCommandActivity extends AppCompatActivity { commandItems.add(new CommandEntry(obj.getString("name"), obj.getString("command"), obj.getString("key"))); } catch (JSONException e) { - e.printStackTrace(); + Log.e("RunCommand", "Error parsing JSON", e); } } diff --git a/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandPlugin.java b/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandPlugin.java index 967ed3f3..b2be261a 100644 --- a/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandPlugin.java @@ -24,6 +24,7 @@ package org.kde.kdeconnect.Plugins.RunCommandPlugin; import android.app.Activity; import android.content.Intent; import android.graphics.drawable.Drawable; +import android.util.Log; import org.json.JSONException; import org.json.JSONObject; @@ -115,7 +116,7 @@ public class RunCommandPlugin extends Plugin { ) ); } catch (JSONException e) { - e.printStackTrace(); + Log.e("RunCommand", "Error parsing JSON", e); } } @@ -125,7 +126,7 @@ public class RunCommandPlugin extends Plugin { context.sendBroadcast(updateWidget); } catch (JSONException e) { - e.printStackTrace(); + Log.e("RunCommand", "Error parsing JSON", e); } for (CommandsChangedCallback aCallback : callbacks) { diff --git a/src/org/kde/kdeconnect/Plugins/SMSPlugin/SMSPlugin.java b/src/org/kde/kdeconnect/Plugins/SMSPlugin/SMSPlugin.java index ba198e93..eb7e93b4 100644 --- a/src/org/kde/kdeconnect/Plugins/SMSPlugin/SMSPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SMSPlugin/SMSPlugin.java @@ -324,8 +324,7 @@ public class SMSPlugin extends Plugin { //TODO: Notify other end } catch (Exception e) { //TODO: Notify other end - Log.e("SMSPlugin", e.getMessage()); - e.printStackTrace(); + Log.e("SMSPlugin", "Exception", e); } } break; diff --git a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java index b811e034..2c2a4ad1 100644 --- a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java @@ -25,6 +25,7 @@ import android.content.ContentResolver; import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; +import android.util.Log; import org.json.JSONException; import org.json.JSONObject; @@ -80,7 +81,7 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref return true; } catch (Exception e) { - e.printStackTrace(); + Log.e("SFTP", "Exception in server.init()", e); return false; } } diff --git a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java index 9feea8f9..611e37ae 100644 --- a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java +++ b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java @@ -30,6 +30,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Environment; +import android.util.Log; import android.util.SparseBooleanArray; import android.view.Menu; import android.view.MenuInflater; @@ -276,7 +277,7 @@ public class SftpSettingsFragment storageInfoList.add(SftpPlugin.StorageInfo.fromJSON(jsonArray.getJSONObject(i))); } } catch (JSONException e) { - e.printStackTrace(); + Log.e("SFTPSettings", "Couldn't load storage info", e); } if (Build.VERSION.SDK_INT <= 19) { diff --git a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.java b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.java index 917e30c3..e6184848 100644 --- a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.java +++ b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.java @@ -116,7 +116,6 @@ class SimpleSftpServer { sshd.start(); started = true; } catch (Exception e) { - e.printStackTrace(); port++; if (port >= ENDPORT) { port = -1; @@ -135,7 +134,7 @@ class SimpleSftpServer { started = false; sshd.stop(true); } catch (Exception e) { - e.printStackTrace(); + Log.e("SFTP", "Exception while stopping the server", e); } } diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/NotificationUpdateCallback.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/NotificationUpdateCallback.java index 5e4a4aae..e742b0dd 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/NotificationUpdateCallback.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/NotificationUpdateCallback.java @@ -3,6 +3,7 @@ package org.kde.kdeconnect.Plugins.SharePlugin; import android.app.NotificationManager; import android.content.Context; import android.content.res.Resources; +import android.util.Log; import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Helpers.NotificationHelper; @@ -75,9 +76,7 @@ class NotificationUpdateCallback extends Device.SendPacketStatusCallback { public void onFailure(Throwable e) { updateDone(false); NotificationHelper.notifyCompat(notificationManager, notificationId, builder.build()); - if (e != null) { - e.printStackTrace(); - } + Log.e("KDEConnect", "Exception", e); } private void updateText() { diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java index 7e68ed74..b99908e1 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -147,8 +147,7 @@ public class SharePlugin extends Plugin { } } catch (Exception e) { - Log.e("SharePlugin", "Exception"); - e.printStackTrace(); + Log.e("SharePlugin", "Exception", e); } return true; @@ -231,7 +230,7 @@ public class SharePlugin extends Plugin { } } } catch (Exception e) { - e.printStackTrace(); + Log.e("SharePlugin", "Error sending files", e); } }).start(); @@ -255,8 +254,7 @@ public class SharePlugin extends Plugin { queuedSendUriList(uriList); } catch (Exception e) { - Log.e("ShareActivity", "Exception"); - e.printStackTrace(); + Log.e("ShareActivity", "Exception", e); } } else if (extras.containsKey(Intent.EXTRA_TEXT)) { diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareSettingsFragment.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareSettingsFragment.java index 82fab763..db3835c9 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareSettingsFragment.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareSettingsFragment.java @@ -127,7 +127,7 @@ public class ShareSettingsFragment extends PluginSettingsFragment { try { getDefaultDestinationDirectory().mkdirs(); } catch (Exception e) { - e.printStackTrace(); + Log.e("KDEConnect", "Exception", e); } return DocumentFile.fromFile(getDefaultDestinationDirectory()); } diff --git a/src/org/kde/kdeconnect/Plugins/SystemvolumePlugin/SystemVolumePlugin.java b/src/org/kde/kdeconnect/Plugins/SystemvolumePlugin/SystemVolumePlugin.java index 3b5b306f..ac39ead4 100644 --- a/src/org/kde/kdeconnect/Plugins/SystemvolumePlugin/SystemVolumePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SystemvolumePlugin/SystemVolumePlugin.java @@ -20,6 +20,8 @@ package org.kde.kdeconnect.Plugins.SystemvolumePlugin; +import android.util.Log; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -75,7 +77,7 @@ public class SystemVolumePlugin extends Plugin { sinks.put(sink.getName(), sink); } } catch (JSONException e) { - e.printStackTrace(); + Log.e("KDEConnect", "Exception", e); } for (SinkListener l : listeners) { diff --git a/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java b/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java index 328cc99e..aa284c38 100644 --- a/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java +++ b/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java @@ -352,7 +352,6 @@ public class DeviceFragment extends Fragment { mActivity.invalidateOptionsMenu(); } catch (IllegalStateException e) { - e.printStackTrace(); //Ignore: The activity was closed while we were trying to update it } catch (ConcurrentModificationException e) { Log.e("DeviceActivity", "ConcurrentModificationException"); diff --git a/src/org/kde/kdeconnect/UserInterface/PairingFragment.java b/src/org/kde/kdeconnect/UserInterface/PairingFragment.java index 64b361d5..c8b97b6b 100644 --- a/src/org/kde/kdeconnect/UserInterface/PairingFragment.java +++ b/src/org/kde/kdeconnect/UserInterface/PairingFragment.java @@ -185,7 +185,6 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb //Restore scroll list.setSelectionFromTop(index, top); } catch (IllegalStateException e) { - e.printStackTrace(); //Ignore: The activity was closed while we were trying to update it } finally { listRefreshCalledThisFrame = false; diff --git a/tests/org/kde/kdeconnect/DeviceTest.java b/tests/org/kde/kdeconnect/DeviceTest.java index a69e939b..1a880a24 100644 --- a/tests/org/kde/kdeconnect/DeviceTest.java +++ b/tests/org/kde/kdeconnect/DeviceTest.java @@ -75,8 +75,7 @@ public class DeviceTest { keyGen.initialize(2048); keyPair = keyGen.genKeyPair(); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/initializeRsaKeys", "Exception"); + Log.e("KDE/initializeRsaKeys", "Exception", e); return; } @@ -162,8 +161,8 @@ public class DeviceTest { keyGen.initialize(2048); keyPair = keyGen.genKeyPair(); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/initializeRsaKeys", "Exception"); + Log.e("KDE/initializeRsaKeys", "Exception", e); + Log.e("KDE/initializeRsaKeys", "Exception", e); return; } device.publicKey = keyPair.getPublic(); @@ -203,8 +202,7 @@ public class DeviceTest { keyGen.initialize(2048); keyPair = keyGen.genKeyPair(); } catch (Exception e) { - e.printStackTrace(); - Log.e("KDE/initializeRsaKeys", "Exception"); + Log.e("KDE/initializeRsaKeys", "Exception", e); } NetworkPacket fakeNetworkPacket = new NetworkPacket(NetworkPacket.PACKET_TYPE_IDENTITY); @@ -251,7 +249,7 @@ public class DeviceTest { method.setAccessible(true); method.invoke(device); } catch (Exception e) { - e.printStackTrace(); + Log.e("KDEConnect", "Exception", e); } assertTrue(device.isPaired()); diff --git a/tests/org/kde/kdeconnect/LanLinkTest.java b/tests/org/kde/kdeconnect/LanLinkTest.java index 72dbad32..79420c48 100644 --- a/tests/org/kde/kdeconnect/LanLinkTest.java +++ b/tests/org/kde/kdeconnect/LanLinkTest.java @@ -142,8 +142,7 @@ public class LanLinkTest { np.setPayload(new NetworkPacket.Payload(socket.getInputStream(), np.getPayloadSize())); } catch (Exception e) { socket.close(); - e.printStackTrace(); - Log.e("KDE/LanLinkTest", "Exception connecting to remote socket"); + Log.e("KDE/LanLinkTest", "Exception connecting to remote socket", e); throw e; } @@ -169,8 +168,7 @@ public class LanLinkTest { input.close(); } catch (Exception e) { - Log.e("Downloader Test", "Exception"); - e.printStackTrace(); + Log.e("Downloader Test", "Exception", e); } } } @@ -233,7 +231,7 @@ public class LanLinkTest { // Wait 1 secs for downloader to finish (if some error, it will continue and assert will fail) downloader.join(1000); } catch (Exception e) { - e.printStackTrace(); + Log.e("Test", "Exception", e); throw e; } assertEquals(new String(data), new String(downloader.getOutputStream().toByteArray()));