From feb45c5f939b2ca615ceca1afebfe156fb2f9c1e Mon Sep 17 00:00:00 2001 From: stom79 Date: Thu, 30 Aug 2018 17:49:26 +0200 Subject: [PATCH] Fixes some crashes --- .../mastodon/activities/ProxyActivity.java | 3 +- .../services/LiveNotificationService.java | 39 +++++++++++-------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ProxyActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ProxyActivity.java index 6762817d3..2c826e186 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ProxyActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ProxyActivity.java @@ -135,7 +135,8 @@ public class ProxyActivity extends BaseActivity { String proxy_passwordVal = proxy_password.getText().toString().trim(); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(Helper.SET_PROXY_HOST, hostVal); - editor.putInt(Helper.SET_PROXY_PORT, Integer.parseInt(portVal)); + if( portVal.matches("\\d+") ) + editor.putInt(Helper.SET_PROXY_PORT, Integer.parseInt(portVal)); editor.putString(Helper.SET_PROXY_LOGIN, proxy_loginVal); editor.putString(Helper.SET_PROXY_PASSWORD, proxy_passwordVal); editor.apply(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java index dab7db302..8b4c5649e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java @@ -106,24 +106,29 @@ public class LiveNotificationService extends Service { int type = sharedpreferences.getInt(Helper.SET_PROXY_TYPE, 0); proxy = null; if( proxyEnabled ){ - String host = sharedpreferences.getString(Helper.SET_PROXY_HOST, "127.0.0.1"); - int port = sharedpreferences.getInt(Helper.SET_PROXY_PORT, 8118); - if( type == 0 ) - proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)); - else - proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(host, port)); - final String login = sharedpreferences.getString(Helper.SET_PROXY_LOGIN, null); - final String pwd = sharedpreferences.getString(Helper.SET_PROXY_PASSWORD, null); - if( login != null) { - Authenticator authenticator = new Authenticator() { - public PasswordAuthentication getPasswordAuthentication() { - assert pwd != null; - return (new PasswordAuthentication(login, - pwd.toCharArray())); - } - }; - Authenticator.setDefault(authenticator); + try{ + String host = sharedpreferences.getString(Helper.SET_PROXY_HOST, "127.0.0.1"); + int port = sharedpreferences.getInt(Helper.SET_PROXY_PORT, 8118); + if( type == 0 ) + proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)); + else + proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(host, port)); + final String login = sharedpreferences.getString(Helper.SET_PROXY_LOGIN, null); + final String pwd = sharedpreferences.getString(Helper.SET_PROXY_PASSWORD, null); + if( login != null) { + Authenticator authenticator = new Authenticator() { + public PasswordAuthentication getPasswordAuthentication() { + assert pwd != null; + return (new PasswordAuthentication(login, + pwd.toCharArray())); + } + }; + Authenticator.setDefault(authenticator); + } + }catch (Exception e){ + proxy = null; } + } if( intent == null || intent.getBooleanExtra("stop", false) ) { stop = true;