From 058bcf1f4a94cb9339306919eabce6167078b354 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Mon, 16 Nov 2015 11:35:11 -0800 Subject: [PATCH] More shortcode fixes for Germany // FREEBIE --- .../securesms/util/ShortCodeUtil.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/org/thoughtcrime/securesms/util/ShortCodeUtil.java b/src/org/thoughtcrime/securesms/util/ShortCodeUtil.java index d5157c0121..7c679a022e 100644 --- a/src/org/thoughtcrime/securesms/util/ShortCodeUtil.java +++ b/src/org/thoughtcrime/securesms/util/ShortCodeUtil.java @@ -27,13 +27,20 @@ public class ShortCodeUtil { PhoneNumberUtil util = PhoneNumberUtil.getInstance(); Phonenumber.PhoneNumber localNumberObject = util.parse(localNumber, null); String localCountryCode = util.getRegionCodeForNumber(localNumberObject); + String bareNumber = number.replaceAll("[^0-9+]", ""); - if (number.replaceAll("[^0-9+]", "").length() <= 4 && !SHORT_COUNTRIES.contains(localCountryCode)) { + // libphonenumber doesn't seem to be correct for Germany + if (bareNumber.length() <= 6 && "DE".equals(localCountryCode)) { return true; - } else { - Phonenumber.PhoneNumber shortCode = util.parse(number, localCountryCode); - return ShortNumberInfo.getInstance().isPossibleShortNumberForRegion(shortCode, localCountryCode); } + + // libphonenumber seems incorrect for Russia and a few other countries with 4 digit short codes. + if (bareNumber.length() <= 4 && !SHORT_COUNTRIES.contains(localCountryCode)) { + return true; + } + + Phonenumber.PhoneNumber shortCode = util.parse(number, localCountryCode); + return ShortNumberInfo.getInstance().isPossibleShortNumberForRegion(shortCode, localCountryCode); } catch (NumberParseException e) { Log.w(TAG, e); return false;