From 04a98d515ba964dab8b01fa27bdbc2ce52530b70 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 4 Jun 2020 00:23:10 +0200 Subject: [PATCH] surround the system-locale-getter by try/catch to protect against errors, on some past versions or in the future; as a default, use Locale.getDefault() as in the past --- .../securesms/util/DynamicLanguage.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/org/thoughtcrime/securesms/util/DynamicLanguage.java b/src/org/thoughtcrime/securesms/util/DynamicLanguage.java index 66a3e440e..8dfdc6d2d 100644 --- a/src/org/thoughtcrime/securesms/util/DynamicLanguage.java +++ b/src/org/thoughtcrime/securesms/util/DynamicLanguage.java @@ -70,14 +70,18 @@ public class DynamicLanguage { // Beware that Locale.getDefault() returns the locale the App was STARTED in, not the locale of the system. // It just happens to be the same for the majority of use cases. private static Locale getDefaultLocale() { - Locale locale; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - locale = Resources.getSystem().getConfiguration().getLocales().get(0); - } else { - //noinspection deprecation - locale = Resources.getSystem().getConfiguration().locale; + Locale locale = null; + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + locale = Resources.getSystem().getConfiguration().getLocales().get(0); + } else { + //noinspection deprecation + locale = Resources.getSystem().getConfiguration().locale; + } + } catch(Exception e) { + e.printStackTrace(); } - return locale; + return locale != null ? locale : Locale.getDefault(); } public static Locale getSelectedLocale(Context context) {