From efe1efdda671ccf5b2d8dc235892a296200839ca Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Sun, 21 Jan 2018 21:01:21 +0100 Subject: [PATCH] Add more specific error message related to ssl connection problems. Signed-off-by: Yahor Berdnikau --- .../moire/ultrasonic/util/BackgroundTask.java | 57 +++++++++---------- ultrasonic/src/main/res/values-es/strings.xml | 2 + ultrasonic/src/main/res/values-fr/strings.xml | 2 + ultrasonic/src/main/res/values-hu/strings.xml | 2 + .../src/main/res/values-pt-rBR/strings.xml | 2 + ultrasonic/src/main/res/values-pt/strings.xml | 2 + ultrasonic/src/main/res/values/strings.xml | 2 + 7 files changed, 40 insertions(+), 29 deletions(-) diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/util/BackgroundTask.java b/ultrasonic/src/main/java/org/moire/ultrasonic/util/BackgroundTask.java index ae47bdcb..f0e32cb0 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/util/BackgroundTask.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/util/BackgroundTask.java @@ -30,6 +30,10 @@ import org.moire.ultrasonic.subsonic.RestErrorMapper; import java.io.FileNotFoundException; import java.io.IOException; +import java.security.cert.CertPathValidatorException; +import java.security.cert.CertificateException; + +import javax.net.ssl.SSLException; /** * @author Sindre Mehus @@ -69,39 +73,34 @@ public abstract class BackgroundTask implements ProgressListener new ErrorDialog(activity, getErrorMessage(error), true); } - protected String getErrorMessage(Throwable error) - { - - if (error instanceof IOException && !Util.isNetworkConnected(activity)) - { - return activity.getResources().getString(R.string.background_task_no_network); - } - - if (error instanceof FileNotFoundException) - { - return activity.getResources().getString(R.string.background_task_not_found); - } - - if (error instanceof JsonParseException) { + protected String getErrorMessage(Throwable error) { + if (error instanceof IOException && !Util.isNetworkConnected(activity)) { + return activity.getResources().getString(R.string.background_task_no_network); + } else if (error instanceof FileNotFoundException) { + return activity.getResources().getString(R.string.background_task_not_found); + } else if (error instanceof JsonParseException) { return activity.getResources().getString(R.string.background_task_parse_error); - } - - if (error instanceof IOException) - { - return activity.getResources().getString(R.string.background_task_network_error); - } - - if (error instanceof SubsonicRESTException) { + } else if (error instanceof SSLException) { + if (error.getCause() instanceof CertificateException && + error.getCause().getCause() instanceof CertPathValidatorException) { + return activity.getResources() + .getString(R.string.background_task_ssl_cert_error, + error.getCause().getCause().getMessage()); + } else { + return activity.getResources().getString(R.string.background_task_ssl_error); + } + } else if (error instanceof IOException) { + return activity.getResources().getString(R.string.background_task_network_error); + } else if (error instanceof SubsonicRESTException) { return RestErrorMapper.getLocalizedErrorMessage((SubsonicRESTException) error, activity); } - String message = error.getMessage(); - if (message != null) - { - return message; - } - return error.getClass().getSimpleName(); - } + String message = error.getMessage(); + if (message != null) { + return message; + } + return error.getClass().getSimpleName(); + } @Override public abstract void updateProgress(final String message); diff --git a/ultrasonic/src/main/res/values-es/strings.xml b/ultrasonic/src/main/res/values-es/strings.xml index 525a11ee..514f1875 100644 --- a/ultrasonic/src/main/res/values-es/strings.xml +++ b/ultrasonic/src/main/res/values-es/strings.xml @@ -6,6 +6,8 @@ Este programa requiere acceso a la red. Por favor enciende la Wi-Fi o la red móvil. Recurso no encontrado. Por favor comprueba la dirección del servidor. No se entiende la respuesta. Por favor comprueba la dirección del servidor. + Error del certificado HTTPS: %1$s. + Excepción de conexión SSL. Compruebe el certificado del servidor. Por favor espera… Marcadores Biblioteca diff --git a/ultrasonic/src/main/res/values-fr/strings.xml b/ultrasonic/src/main/res/values-fr/strings.xml index 54b0c249..0c6616f6 100644 --- a/ultrasonic/src/main/res/values-fr/strings.xml +++ b/ultrasonic/src/main/res/values-fr/strings.xml @@ -6,6 +6,8 @@ Cette application requiert un accès au réseau. Veuillez activer le Wi-Fi ou le réseau mobile. Ressources introuvables. Veuillez vérifier l\'adresse du serveur. Réponse incorrecte. Veuillez vérifier l\'adresse du serveur. + Erreur de certificat HTTPS: %1$s. + Exception de connexion SSL. Veuillez vérifier le certificat du serveur. Veuillez patienter… Signets Bibliothèque musicale diff --git a/ultrasonic/src/main/res/values-hu/strings.xml b/ultrasonic/src/main/res/values-hu/strings.xml index 0bf3027c..571ad7fc 100644 --- a/ultrasonic/src/main/res/values-hu/strings.xml +++ b/ultrasonic/src/main/res/values-hu/strings.xml @@ -6,6 +6,8 @@ Az alkalmazás hálózati hozzáférést igényel. Kérjük, kapcsolja be a Wi-Fi-t vagy a mobilhálózatot! Az erőforrás nem található! Kérjük, ellenőrizze a kiszolgáló címét! Értelmezhetetlen válasz! Kérjük, ellenőrizze a kiszolgáló címét! + HTTPS tanúsítványhiba: %1$s. + SSL kapcsolat kivétel. Kérjük, ellenőrizze a szerver tanúsítványát. Kérem várjon!… Könyvjelzők Médiakönyvtár diff --git a/ultrasonic/src/main/res/values-pt-rBR/strings.xml b/ultrasonic/src/main/res/values-pt-rBR/strings.xml index 2fe7fba0..88dd330a 100644 --- a/ultrasonic/src/main/res/values-pt-rBR/strings.xml +++ b/ultrasonic/src/main/res/values-pt-rBR/strings.xml @@ -6,6 +6,8 @@ Este aplicativo requer acesso à rede. Ligue o Wi-Fi ou a rede de dados. Recurso não encontrado. Verifique o endereço do servidor. Não entendi a resposta. Verifique o endereço do servidor. + Erro de certificado HTTPS: %1$s. + Exceção de conexão SSL. Verifique o certificado do servidor. Por favor aguarde… Favoritos Biblioteca de Mídia diff --git a/ultrasonic/src/main/res/values-pt/strings.xml b/ultrasonic/src/main/res/values-pt/strings.xml index 3908daca..9286d0e5 100644 --- a/ultrasonic/src/main/res/values-pt/strings.xml +++ b/ultrasonic/src/main/res/values-pt/strings.xml @@ -6,6 +6,8 @@ Este aplicativo requer acesso à rede. Ligue o Wi-Fi ou a rede de dados. Recurso não encontrado. Verifique o endereço do servidor. Não entendi a resposta. Verifique o endereço do servidor. + Erro de certificado HTTPS: %1$s. + Exceção de conexão SSL. Verifique o certificado do servidor. Por favor aguarde… Favoritos Biblioteca de Mídia diff --git a/ultrasonic/src/main/res/values/strings.xml b/ultrasonic/src/main/res/values/strings.xml index 91777b4f..4748a3eb 100644 --- a/ultrasonic/src/main/res/values/strings.xml +++ b/ultrasonic/src/main/res/values/strings.xml @@ -6,6 +6,8 @@ This program requires network access. Please turn on Wi-Fi or mobile network. Resource not found. Please check the server address. Didn\'t understand the reply. Please check the server address. + HTTPS certificate error: %1$s. + SSL connection exception. Please check server certificate. Please wait… Bookmarks Media Library