From 559bcfc6a5b2bb3e1c2f79954a909eb3bf63d972 Mon Sep 17 00:00:00 2001 From: Markus <8398165+mqus@users.noreply.github.com> Date: Fri, 13 Dec 2019 21:15:16 +0100 Subject: [PATCH] Remove commented-out code and hide stacktraces in release mode --- .../org/schabi/newpipe/DownloaderImpl.java | 4 ++- .../newpipe/util/TLSSocketFactoryCompat.java | 30 ++----------------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java index cceb662f7..7e4ac304e 100644 --- a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java +++ b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java @@ -35,6 +35,8 @@ import okhttp3.OkHttpClient; import okhttp3.RequestBody; import okhttp3.ResponseBody; +import static org.schabi.newpipe.MainActivity.DEBUG; + public class DownloaderImpl extends Downloader { public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"; @@ -211,7 +213,7 @@ public class DownloaderImpl extends Downloader { builder.connectionSpecs(Arrays.asList(legacyTLS, ConnectionSpec.CLEARTEXT)); } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) { - e.printStackTrace(); + if (DEBUG) e.printStackTrace(); } } } diff --git a/app/src/main/java/org/schabi/newpipe/util/TLSSocketFactoryCompat.java b/app/src/main/java/org/schabi/newpipe/util/TLSSocketFactoryCompat.java index 2f6a650ff..d8b6f78f5 100644 --- a/app/src/main/java/org/schabi/newpipe/util/TLSSocketFactoryCompat.java +++ b/app/src/main/java/org/schabi/newpipe/util/TLSSocketFactoryCompat.java @@ -13,6 +13,8 @@ import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; +import static org.schabi.newpipe.MainActivity.DEBUG; + /** * This is an extension of the SSLSocketFactory which enables TLS 1.2 and 1.1. @@ -49,7 +51,7 @@ public class TLSSocketFactoryCompat extends SSLSocketFactory { try { HttpsURLConnection.setDefaultSSLSocketFactory(getInstance()); } catch (NoSuchAlgorithmException | KeyManagementException e) { - e.printStackTrace(); + if (DEBUG) e.printStackTrace(); } } @@ -95,33 +97,7 @@ public class TLSSocketFactoryCompat extends SSLSocketFactory { private Socket enableTLSOnSocket(Socket socket) { if (socket != null && (socket instanceof SSLSocket)) { - /* - //Create list of supported protocols - ArrayList supportedProtocols = new ArrayList<>(); - for (String protocol : ((SSLSocket)socket).getEnabledProtocols()) { - - //Log.d("TLSSocketFactory", "Supported protocol:" + protocol); - //Only add TLS protocols (don't want ot support older SSL versions) - if (protocol.toUpperCase().contains("TLS")) { - supportedProtocols.add(protocol); - } - } - //Force add TLSv1.1 and 1.2 if not already added - if (!supportedProtocols.contains("TLSv1.1")) { - supportedProtocols.add("TLSv1.1"); - } - if (!supportedProtocols.contains("TLSv1.2")) { - supportedProtocols.add("TLSv1.2"); - } - - String[] protocolArray = supportedProtocols.toArray(new String[supportedProtocols.size()]); - - //enable protocols in our list - //((SSLSocket)socket).setEnabledProtocols(protocolArray); - */ - // OR: only enable TLS 1.1 and 1.2! ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1.1", "TLSv1.2"}); - } return socket; }